fake_sqs 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ffdf71e44c5de564702286a5fb677693ffa8098
4
- data.tar.gz: e47abd738c5707b3fef71b580e847b08ea26ffa2
3
+ metadata.gz: 909e1da7c44403638eb5d95fe363a7d2c7282135
4
+ data.tar.gz: 94f87e79eef035cf8c6d89f0de61d1cd4e5f951c
5
5
  SHA512:
6
- metadata.gz: 56db094e2373419a92f3d3671ed30bb10ebd56974f7bbf7e00befe8f84762d0cb0c2957d6649e21ac2823368ed6ecbcd9bfc93d589c10078de34d120234cccc7
7
- data.tar.gz: ef9b9117d913f6f813b98621143f6e3dfa3fb5623d765a0bf1590b00eaea3f553bd14315a90b1949901797e609964a6d90aefb33696e951c53a180d5e755d008
6
+ metadata.gz: 9ace909c2bcf251ea0234b0ceb5804bf5b5780765d41ea838bff230a7a8765caa0a32b6792eace91783b8a0a73022d93bf5e5d815236e9ec1a8e8aa1f236014f
7
+ data.tar.gz: 2e7baaa00ba1fe6da88e20276edad298813f7477c3be0fb82bc0c988e6ddfab7cd33ff211c058677da08b53633369b80b0ef6de3382a7bed7463d78d0af85b43
data/README.md CHANGED
@@ -6,7 +6,7 @@ testing, just like you would have a local database running. Fake SQS doesn't
6
6
  persist anything, not even the queues themselves. You'll have to create the
7
7
  queues everytime you start it.
8
8
 
9
- This implementation is **not complete** yet.
9
+ This implementation is **not complete** yet, but should be useful already.
10
10
 
11
11
  Done so far are:
12
12
 
@@ -17,6 +17,7 @@ Done so far are:
17
17
  * Send messages (and in batch)
18
18
  * Receive messages (and in batch)
19
19
  * Deleting messages (and in batch)
20
+ * Changing queue attributes (but not all, and no validation)
20
21
 
21
22
  Certain bits are left off on purpose, to make it easier to work with, such as:
22
23
 
@@ -27,12 +28,13 @@ Certain bits are left off on purpose, to make it easier to work with, such as:
27
28
  Other parts are just not done yet:
28
29
 
29
30
  * Permissions
30
- * Changing queue attributes
31
31
  * Changing message visibility
32
32
  * Error handling
33
33
 
34
34
  So, actually, just the basics are implemented at this point.
35
35
 
36
+ PS. There is also [Fake SNS] [fake_sns].
37
+
36
38
  ## Usage
37
39
 
38
40
  To install:
@@ -147,3 +149,4 @@ end
147
149
 
148
150
  [fake_dynamo]: https://github.com/ananthakumaran/fake_dynamo
149
151
  [aws-sdk]: https://github.com/amazonwebservices/aws-sdk-for-ruby
152
+ [fake_sns]: https://github.com/yourkarma/fake_sns
data/bin/fake_sqs CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
+
3
5
  require 'fake_sqs'
4
6
  require 'optparse'
5
7
 
@@ -0,0 +1,25 @@
1
+ module FakeSQS
2
+ module Actions
3
+ class GetQueueAttributes
4
+
5
+ def initialize(options = {})
6
+ @server = options.fetch(:server)
7
+ @queues = options.fetch(:queues)
8
+ @responder = options.fetch(:responder)
9
+ end
10
+
11
+ def call(queue_name, params)
12
+ queue = @queues.get(queue_name)
13
+ @responder.call :GetQueueAttributes do |xml|
14
+ queue.attributes.each do |name, value|
15
+ xml.Attribute do
16
+ xml.Name name
17
+ xml.Value value
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module FakeSQS
2
+ module Actions
3
+ class SetQueueAttributes
4
+
5
+ def initialize(options = {})
6
+ @server = options.fetch(:server)
7
+ @queues = options.fetch(:queues)
8
+ @responder = options.fetch(:responder)
9
+ end
10
+
11
+ def call(queue_name, params)
12
+ queue = @queues.get(queue_name)
13
+ results = {}
14
+ params.each do |key, value|
15
+ if key =~ /\AAttribute\.(\d+)\.Name\z/
16
+ results[value] = params.fetch("Attribute.#{$1}.Value")
17
+ end
18
+ end
19
+ queue.attributes.merge!(results)
20
+ @responder.call :SetQueueAttributes
21
+ end
22
+
23
+ end
24
+ end
25
+ end
data/lib/fake_sqs/api.rb CHANGED
@@ -7,6 +7,8 @@ require 'fake_sqs/actions/receive_message'
7
7
  require 'fake_sqs/actions/delete_message'
8
8
  require 'fake_sqs/actions/delete_message_batch'
9
9
  require 'fake_sqs/actions/send_message_batch'
10
+ require 'fake_sqs/actions/get_queue_attributes'
11
+ require 'fake_sqs/actions/set_queue_attributes'
10
12
 
11
13
  module FakeSQS
12
14
 
@@ -6,11 +6,13 @@ module FakeSQS
6
6
 
7
7
  class Queue
8
8
 
9
- attr_reader :name, :messages, :message_factory, :messages_in_flight
9
+ attr_reader :name, :messages, :message_factory, :messages_in_flight, :attributes
10
10
 
11
11
  def initialize(options = {})
12
12
  @name = options.fetch("QueueName")
13
13
  @message_factory = options.fetch(:message_factory)
14
+ @attributes = {}
15
+ @attributes["QueueArn"] = "arn:aws:sqs:us-east-1:#{SecureRandom.hex}:#{@name}"
14
16
  reset
15
17
  end
16
18
 
@@ -42,7 +44,7 @@ module FakeSQS
42
44
  end
43
45
 
44
46
  def delete_message(receipt)
45
- message = messages_in_flight.delete(receipt)
47
+ messages_in_flight.delete(receipt)
46
48
  end
47
49
 
48
50
  def reset
@@ -1,3 +1,3 @@
1
1
  module FakeSQS
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -7,6 +7,7 @@ describe "Actions for Queues", :sqs do
7
7
  specify "CreateQueue" do
8
8
  queue = sqs.queues.create("test-create-queue")
9
9
  queue.url.should eq "http://0.0.0.0:4568/test-create-queue"
10
+ queue.arn.should match %r"arn:aws:sqs:us-east-1:.+:test-create-queue"
10
11
  end
11
12
 
12
13
  specify "GetQueueUrl" do
@@ -41,4 +42,20 @@ describe "Actions for Queues", :sqs do
41
42
  sqs.should have(0).queues
42
43
  end
43
44
 
45
+ specify "SetQueueAttributes / GetQueueAttributes" do
46
+
47
+ policy = AWS::SQS::Policy.new
48
+ policy.allow(
49
+ :actions => ['s3:PutObject'],
50
+ :resources => "arn:aws:s3:::mybucket/mykey/*",
51
+ :principals => :any
52
+ ).where(:acl).is("public-read")
53
+
54
+ queue = sqs.queues.create("my-queue")
55
+ queue.policy = policy
56
+
57
+ reloaded_queue = sqs.queues.named("my-queue")
58
+ reloaded_queue.policy.should eq policy
59
+ end
60
+
44
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_sqs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - iain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -158,11 +158,13 @@ files:
158
158
  - lib/fake_sqs/actions/delete_message.rb
159
159
  - lib/fake_sqs/actions/delete_message_batch.rb
160
160
  - lib/fake_sqs/actions/delete_queue.rb
161
+ - lib/fake_sqs/actions/get_queue_attributes.rb
161
162
  - lib/fake_sqs/actions/get_queue_url.rb
162
163
  - lib/fake_sqs/actions/list_queues.rb
163
164
  - lib/fake_sqs/actions/receive_message.rb
164
165
  - lib/fake_sqs/actions/send_message.rb
165
166
  - lib/fake_sqs/actions/send_message_batch.rb
167
+ - lib/fake_sqs/actions/set_queue_attributes.rb
166
168
  - lib/fake_sqs/api.rb
167
169
  - lib/fake_sqs/catch_errors.rb
168
170
  - lib/fake_sqs/error_response.rb