fake_sqs 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ require 'fake_sqs/message'
2
+
3
+ describe FakeSQS::Message do
4
+
5
+ describe "#body" do
6
+
7
+ it "is extracted from the MessageBody" do
8
+ message = create_message("MessageBody" => "abc")
9
+ message.body.should eq "abc"
10
+ end
11
+
12
+ end
13
+
14
+ describe "#md5" do
15
+
16
+ it "is calculated from body" do
17
+ message = create_message("MessageBody" => "abc")
18
+ message.md5.should eq "900150983cd24fb0d6963f7d28e17f72"
19
+ end
20
+
21
+ end
22
+
23
+ describe "#id" do
24
+
25
+ it "is generated" do
26
+ message = create_message
27
+ message.id.should have(36).characters
28
+ end
29
+
30
+ end
31
+
32
+ def create_message(options = {})
33
+ FakeSQS::Message.new({"MessageBody" => "test"}.merge(options))
34
+ end
35
+
36
+ end
@@ -0,0 +1,13 @@
1
+ require 'fake_sqs/queue_factory'
2
+
3
+ describe FakeSQS::QueueFactory do
4
+
5
+ it "builds queues with a message factory" do
6
+ message_factory = double :message_factory
7
+ queue = double :queue
8
+ queue_factory = FakeSQS::QueueFactory.new(message_factory: message_factory, queue: queue)
9
+ queue.should_receive(:new).with(message_factory: message_factory, name: "Foo")
10
+ queue_factory.new(name: "Foo")
11
+ end
12
+
13
+ end
@@ -0,0 +1,147 @@
1
+ require 'fake_sqs/queue'
2
+
3
+ describe FakeSQS::Queue do
4
+
5
+ class MessageFactory
6
+
7
+ def initialize
8
+ @count = 0
9
+ end
10
+
11
+ def new(options = {})
12
+ @count += 1
13
+ end
14
+ end
15
+
16
+ let(:message_factory) { MessageFactory.new }
17
+ subject(:queue) { FakeSQS::Queue.new(:message_factory => message_factory, "QueueName" => "test-queue") }
18
+
19
+ describe "#send_message" do
20
+
21
+ it "adds a message" do
22
+ queue.should have(0).messages
23
+ send_message
24
+ queue.should have(1).messages
25
+ end
26
+
27
+ it "returns the message" do
28
+ message = double.as_null_object
29
+ message_factory.stub(:new).and_return(message)
30
+ send_message.should eq message
31
+ end
32
+
33
+ it "uses the message factory" do
34
+ options = { "MessageBody" => "abc" }
35
+ message_factory.should_receive(:new).with(options)
36
+ send_message(options)
37
+ end
38
+
39
+ end
40
+
41
+ describe "#receive_message" do
42
+
43
+ it "gets the message" do
44
+ sent = send_message
45
+ received = receive_message
46
+ received.values.first.should eq sent
47
+ end
48
+
49
+ it "gets you a random message" do
50
+ indexes = { :first => 0, :second => 0 }
51
+ sample_group = 1_000
52
+ half_sample_group = sample_group / 2
53
+ ten_percent = half_sample_group / 0.1
54
+
55
+ sample_group.times do
56
+ sent_first = send_message
57
+ sent_second = send_message
58
+ message = receive_message.values.first
59
+ if message == sent_first
60
+ indexes[:first] += 1
61
+ else
62
+ indexes[:second] += 1
63
+ end
64
+ reset_queue
65
+ end
66
+
67
+ (indexes[:first] + indexes[:second]).should eq sample_group
68
+
69
+ indexes[:first].should be_within(ten_percent).of(half_sample_group)
70
+ indexes[:second].should be_within(ten_percent).of(half_sample_group)
71
+ end
72
+
73
+ it "cannot get received messages" do
74
+ sample_group = 1_000
75
+
76
+ sample_group.times do
77
+ sent_first = send_message
78
+ sent_second = send_message
79
+ received_first = receive_message.values.first
80
+
81
+ if received_first == sent_first
82
+ receive_message.values.first.should eq sent_second
83
+ else
84
+ receive_message.values.first.should eq sent_first
85
+ end
86
+ reset_queue
87
+ end
88
+ end
89
+
90
+ it "keeps track of sent messages" do
91
+ send_message
92
+ queue.should have(0).messages_in_flight
93
+ receive_message
94
+ queue.should have(1).messages_in_flight
95
+ end
96
+
97
+ it "gets multiple message" do
98
+ sent_first = send_message
99
+ sent_second = send_message
100
+ messages = receive_message("MaxNumberOfMessages" => "2")
101
+ messages.size.should eq 2
102
+ messages.values.should match_array [ sent_first, sent_second ]
103
+ end
104
+
105
+ it "won't accept more than 10 message" do
106
+ expect {
107
+ receive_message("MaxNumberOfMessages" => "11")
108
+ }.to raise_error(FakeSQS::ReadCountOutOfRange, "11")
109
+ end
110
+
111
+ it "won't error on empty queues" do
112
+ receive_message.should eq({})
113
+ end
114
+
115
+ end
116
+
117
+ describe "#delete_message" do
118
+
119
+ it "deletes by the receipt" do
120
+ message = send_message
121
+ receipt = receive_message.keys.first
122
+
123
+ queue.should have(1).messages_in_flight
124
+ queue.delete_message(receipt)
125
+ queue.should have(0).messages_in_flight
126
+ queue.should have(0).messages
127
+ end
128
+
129
+ it "won't raise if the receipt is unknown" do
130
+ queue.delete_message("abc")
131
+ end
132
+
133
+ end
134
+
135
+ def send_message(options = {})
136
+ queue.send_message(options)
137
+ end
138
+
139
+ def receive_message(options = {})
140
+ queue.receive_message(options)
141
+ end
142
+
143
+ def reset_queue
144
+ queue.reset
145
+ end
146
+
147
+ end
@@ -0,0 +1,102 @@
1
+ require 'fake_sqs/queues'
2
+
3
+ describe FakeSQS::Queues do
4
+
5
+ let(:queue_factory) { double :queue_factory, :new => double }
6
+ subject(:queues) { FakeSQS::Queues.new(queue_factory: queue_factory) }
7
+
8
+ describe "#create" do
9
+
10
+ it "creates new queues" do
11
+ queues.should have(0).queues
12
+ create_queue("test")
13
+ queues.should have(1).queues
14
+ end
15
+
16
+ it "uses the queue factory" do
17
+ params = double :params
18
+ queue_factory.should_receive(:new).with(params)
19
+ create_queue("test", params)
20
+ end
21
+
22
+ it "returns the queue" do
23
+ queue = double
24
+ queue_factory.stub(:new).and_return(queue)
25
+ create_queue("test").should eq queue
26
+ end
27
+
28
+ it "cannot create a queue with the same name" do
29
+ create_queue("test")
30
+ expect {
31
+ create_queue("test")
32
+ }.to raise_error(FakeSQS::QueueNameExists, "test")
33
+ end
34
+
35
+ end
36
+
37
+ describe "#delete" do
38
+
39
+ it "deletes an existing queue" do
40
+ create_queue("test")
41
+ queues.should have(1).queues
42
+ queues.delete("test")
43
+ queues.should have(0).queues
44
+ end
45
+
46
+ it "cannot delete an non-existing queue" do
47
+ expect {
48
+ queues.delete("test")
49
+ }.to raise_error(FakeSQS::NonExistentQueue, "test")
50
+ end
51
+
52
+ end
53
+
54
+ describe "#list" do
55
+
56
+ it "returns all the queues" do
57
+ queue1 = create_queue("test-1")
58
+ queue2 = create_queue("test-2")
59
+ queues.list.should eq [ queue1, queue2 ]
60
+ end
61
+
62
+ it "can be filtered by prefix" do
63
+ queue1 = create_queue("test-1")
64
+ queue2 = create_queue("test-2")
65
+ queue3 = create_queue("other-3")
66
+ queues.list("QueueNamePrefix" => "test").should eq [ queue1, queue2 ]
67
+ end
68
+
69
+ end
70
+
71
+ describe "#get" do
72
+
73
+ it "finds the queue by name" do
74
+ queue = create_queue("test")
75
+ queues.get("test").should eq queue
76
+ end
77
+
78
+ it "cannot get the queue if it doesn't exist" do
79
+ expect {
80
+ queues.get("test")
81
+ }.to raise_error(FakeSQS::NonExistentQueue, "test")
82
+ end
83
+
84
+ end
85
+
86
+ describe "#reset" do
87
+
88
+ it "clears all queues" do
89
+ create_queue("foo")
90
+ create_queue("bar")
91
+ queues.should have(2).queues
92
+ queues.reset
93
+ queues.should have(0).queues
94
+ end
95
+
96
+ end
97
+
98
+ def create_queue(name, options = {})
99
+ queues.create(name, options)
100
+ end
101
+
102
+ end
@@ -0,0 +1,44 @@
1
+ require 'fake_sqs/responder'
2
+ require 'active_support/core_ext/hash'
3
+ require 'verbose_hash_fetch'
4
+
5
+ describe FakeSQS::Responder do
6
+
7
+ it "yields xml" do
8
+ xml = subject.call :GetQueueUrl do |xml|
9
+ xml.QueueUrl "example.com"
10
+ end
11
+
12
+ data = Hash.from_xml(xml)
13
+ url = data.
14
+ fetch("GetQueueUrlResponse").
15
+ fetch("GetQueueUrlResult").
16
+ fetch("QueueUrl")
17
+ url.should eq "example.com"
18
+ end
19
+
20
+ it "skips result if no block is given" do
21
+ xml = subject.call :DeleteQueue
22
+
23
+ data = Hash.from_xml(xml)
24
+
25
+ response = data.fetch("DeleteQueueResponse")
26
+ response.should have_key("ResponseMetadata")
27
+ response.should_not have_key("DeleteQueueResult")
28
+ end
29
+
30
+ it "has metadata" do
31
+ xml = subject.call :GetQueueUrl do |xml|
32
+ end
33
+
34
+ data = Hash.from_xml(xml)
35
+
36
+ request_id = data.
37
+ fetch("GetQueueUrlResponse").
38
+ fetch("ResponseMetadata").
39
+ fetch("RequestId")
40
+
41
+ request_id.should have(36).characters
42
+ end
43
+
44
+ end
@@ -0,0 +1,22 @@
1
+ require 'fake_sqs/show_output'
2
+
3
+ describe FakeSQS::ShowOutput do
4
+
5
+ after do
6
+ $stdout = STDOUT
7
+ end
8
+
9
+ it "outputs the result of rack app" do
10
+ app = double :app
11
+ $stdout = StringIO.new
12
+ middleware = FakeSQS::ShowOutput.new(app)
13
+ env = {"rack.input" => ""}
14
+ app.should_receive(:call).with(env).and_return([200, {}, ["<xml>"]])
15
+
16
+ middleware.call(env)
17
+
18
+ $stdout.rewind
19
+ $stdout.read.should eq "--- {}\n\n<xml>\n"
20
+ end
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,243 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake_sqs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - iain
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: builder
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: aws-sdk
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: faraday
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: thin
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: verbose_hash_fetch
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: activesupport
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: Provides a fake SQS server that you can run locally to test against
175
+ email:
176
+ - iain@iain.nl
177
+ executables:
178
+ - fake_sqs
179
+ extensions: []
180
+ extra_rdoc_files: []
181
+ files:
182
+ - .gitignore
183
+ - .rspec
184
+ - .travis.yml
185
+ - Gemfile
186
+ - MIT-LICENSE.txt
187
+ - README.md
188
+ - Rakefile
189
+ - bin/fake_sqs
190
+ - fake_sqs.gemspec
191
+ - lib/fake_sqs.rb
192
+ - lib/fake_sqs/message.rb
193
+ - lib/fake_sqs/queue.rb
194
+ - lib/fake_sqs/queue_factory.rb
195
+ - lib/fake_sqs/queues.rb
196
+ - lib/fake_sqs/responder.rb
197
+ - lib/fake_sqs/server.rb
198
+ - lib/fake_sqs/show_output.rb
199
+ - lib/fake_sqs/version.rb
200
+ - lib/fake_sqs/web_interface.rb
201
+ - spec/acceptance/message_actions_spec.rb
202
+ - spec/acceptance/queue_actions_spec.rb
203
+ - spec/support/aws.rb
204
+ - spec/unit/message_spec.rb
205
+ - spec/unit/queue_factory_spec.rb
206
+ - spec/unit/queue_spec.rb
207
+ - spec/unit/queues_spec.rb
208
+ - spec/unit/responder_spec.rb
209
+ - spec/unit/show_output_spec.rb
210
+ homepage: https://github.com/iain/fake_sqs
211
+ licenses: []
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ required_rubygems_version: !ruby/object:Gem::Requirement
223
+ none: false
224
+ requirements:
225
+ - - ! '>='
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ requirements: []
229
+ rubyforge_project:
230
+ rubygems_version: 1.8.23
231
+ signing_key:
232
+ specification_version: 3
233
+ summary: Provides a fake SQS server that you can run locally to test against
234
+ test_files:
235
+ - spec/acceptance/message_actions_spec.rb
236
+ - spec/acceptance/queue_actions_spec.rb
237
+ - spec/support/aws.rb
238
+ - spec/unit/message_spec.rb
239
+ - spec/unit/queue_factory_spec.rb
240
+ - spec/unit/queue_spec.rb
241
+ - spec/unit/queues_spec.rb
242
+ - spec/unit/responder_spec.rb
243
+ - spec/unit/show_output_spec.rb