fake_sqs 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/README.md +27 -0
- data/Rakefile +26 -1
- data/bin/fake_sqs +18 -34
- data/lib/fake_sqs.rb +44 -4
- data/lib/fake_sqs/actions/set_queue_attributes.rb +1 -0
- data/lib/fake_sqs/api.rb +5 -2
- data/lib/fake_sqs/daemonize.rb +30 -0
- data/lib/fake_sqs/file_database.rb +83 -0
- data/lib/fake_sqs/memory_database.rb +36 -0
- data/lib/fake_sqs/message.rb +9 -7
- data/lib/fake_sqs/queue.rb +15 -6
- data/lib/fake_sqs/queues.rb +25 -12
- data/lib/fake_sqs/test_integration.rb +22 -2
- data/lib/fake_sqs/version.rb +1 -1
- data/spec/spec_helper.rb +4 -2
- data/spec/unit/api_spec.rb +4 -2
- data/spec/unit/queues_spec.rb +10 -8
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07cc7d69931207649b20dc94e4d3522023a4e110
|
4
|
+
data.tar.gz: 6c895b6844061cd9e054777cd19b369bccdca806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e638d676fc1ba7cab88664b90bdbd5be94db189800e5507799e42fa546f99f7ee4f5a6d823673e54f86d69b1b6faa2788164304589e18e64063dcc12ef678b66
|
7
|
+
data.tar.gz: c6aebf4bffbe5d0f7a7fdc0025b4c121ff0f0fd01a4413d76e28f4575c3d156424d7a78a486a1cbfe87f142321e8dd100ac79390b20ad7abc01fe50ab2ed3434
|
data/.rspec
CHANGED
data/README.md
CHANGED
@@ -55,6 +55,15 @@ To configure, see the options in the help:
|
|
55
55
|
$ fake_sqs --help
|
56
56
|
```
|
57
57
|
|
58
|
+
By default, FakeSQS uses an in-memory database (just a hash actually). To make
|
59
|
+
it persistant, run with:
|
60
|
+
|
61
|
+
```
|
62
|
+
$ fake_sqs --database /path/to/database.yml
|
63
|
+
```
|
64
|
+
|
65
|
+
Messages are not persisted, just the queues.
|
66
|
+
|
58
67
|
This is an example of how to configure the official [aws-sdk gem] [aws-sdk], to
|
59
68
|
let it talk to Fake SQS.
|
60
69
|
|
@@ -146,6 +155,24 @@ describe "something with sqs", :sqs do
|
|
146
155
|
end
|
147
156
|
```
|
148
157
|
|
158
|
+
## Development
|
159
|
+
|
160
|
+
Run all the specs:
|
161
|
+
|
162
|
+
```
|
163
|
+
$ rake
|
164
|
+
```
|
165
|
+
|
166
|
+
This will run the unit tests, then the acceptance tests for both types of
|
167
|
+
storage (in-memory and on disk).
|
168
|
+
|
169
|
+
When debugging an acceptance test, you can run it like this, which will redirect
|
170
|
+
output to the console:
|
171
|
+
|
172
|
+
```
|
173
|
+
$ DEBUG=true SQS_DATABASE=tmp/sqs.yml rspec spec/acceptance
|
174
|
+
```
|
175
|
+
|
149
176
|
|
150
177
|
[fake_dynamo]: https://github.com/ananthakumaran/fake_dynamo
|
151
178
|
[aws-sdk]: https://github.com/amazonwebservices/aws-sdk-for-ruby
|
data/Rakefile
CHANGED
@@ -1,6 +1,31 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
|
+
require "tempfile"
|
3
4
|
require 'rspec/core/rake_task'
|
4
|
-
|
5
|
+
|
6
|
+
namespace :spec do
|
7
|
+
|
8
|
+
desc "Run only unit specs"
|
9
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
10
|
+
t.pattern = "spec/unit"
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Run specs with in-memory database"
|
14
|
+
RSpec::Core::RakeTask.new(:memory) do |t|
|
15
|
+
ENV["SQS_DATABASE"] = ":memory:"
|
16
|
+
t.pattern = "spec/acceptance"
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Run specs with file database"
|
20
|
+
RSpec::Core::RakeTask.new(:file) do |t|
|
21
|
+
file = Tempfile.new(["rspec-sqs", ".yml"], encoding: "utf-8")
|
22
|
+
ENV["SQS_DATABASE"] = file.path
|
23
|
+
t.pattern = "spec/acceptance"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Run spec suite with both in-memory and file"
|
29
|
+
task :spec => ["spec:unit", "spec:memory", "spec:file"]
|
5
30
|
|
6
31
|
task :default => :spec
|
data/bin/fake_sqs
CHANGED
@@ -6,15 +6,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
6
|
require 'fake_sqs'
|
7
7
|
require 'optparse'
|
8
8
|
|
9
|
-
options = {
|
9
|
+
options = {
|
10
|
+
:port => 4568,
|
11
|
+
:host => "0.0.0.0",
|
12
|
+
:verbose => false,
|
13
|
+
:daemonize => false,
|
14
|
+
:database => ":memory:"
|
15
|
+
}
|
10
16
|
|
11
17
|
parser = OptionParser.new do |o|
|
12
18
|
|
19
|
+
o.on "--database DATABASE", "Where to store the database (default: #{options[:database]})" do |database|
|
20
|
+
options[:database] = database
|
21
|
+
end
|
22
|
+
|
13
23
|
o.on "-p", "--port PORT", Integer, "Port to use (default: #{options[:port]})" do |port|
|
14
24
|
options[:port] = port
|
15
25
|
end
|
16
26
|
|
17
|
-
o.on "-o", "--bind HOST", "Host to bind to (default:
|
27
|
+
o.on "-o", "--bind HOST", "Host to bind to (default: #{options[:host]})" do |host|
|
18
28
|
options[:host] = host
|
19
29
|
end
|
20
30
|
|
@@ -30,10 +40,14 @@ parser = OptionParser.new do |o|
|
|
30
40
|
options[:daemonize] = daemonize
|
31
41
|
end
|
32
42
|
|
33
|
-
o.on "-v", "--[no]
|
43
|
+
o.on "-v", "--[no-]verbose", "Shows input parameters and output XML" do |verbose|
|
34
44
|
options[:verbose] = verbose
|
35
45
|
end
|
36
46
|
|
47
|
+
o.on "--log FILE", "Redirect output to this logfile (default: console)" do |logfile|
|
48
|
+
options[:log] = logfile
|
49
|
+
end
|
50
|
+
|
37
51
|
o.on_tail "--version", "Shows the version" do
|
38
52
|
puts "fake_sqs version #{FakeSQS::VERSION}"
|
39
53
|
exit
|
@@ -48,34 +62,4 @@ end
|
|
48
62
|
|
49
63
|
parser.parse!
|
50
64
|
|
51
|
-
|
52
|
-
|
53
|
-
if options[:verbose]
|
54
|
-
require 'fake_sqs/show_output'
|
55
|
-
app.use FakeSQS::ShowOutput
|
56
|
-
end
|
57
|
-
|
58
|
-
if options[:daemonize]
|
59
|
-
Process.daemon(true, true)
|
60
|
-
end
|
61
|
-
|
62
|
-
if (pid = options[:pid])
|
63
|
-
if File.exist?(pid)
|
64
|
-
existing_pid = File.open(pid, 'r').read.chomp.to_i
|
65
|
-
running = Process.getpgid(existing_pid) rescue false
|
66
|
-
if running
|
67
|
-
warn "Error, Process #{existing_pid} already running"
|
68
|
-
exit 1
|
69
|
-
else
|
70
|
-
warn "Cleaning up stale pid at #{pid}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
File.open(pid, 'w') { |f| f.write(Process.pid) }
|
74
|
-
end
|
75
|
-
|
76
|
-
app.set :port, options[:port]
|
77
|
-
app.set :bind, options[:host]
|
78
|
-
app.set :server, options[:server] if options[:server]
|
79
|
-
server = FakeSQS.server(port: options[:port], host: options[:host])
|
80
|
-
app.set :api, FakeSQS.api(server: server)
|
81
|
-
app.run!
|
65
|
+
FakeSQS.to_rack(options).run!
|
data/lib/fake_sqs.rb
CHANGED
@@ -8,24 +8,56 @@ require 'fake_sqs/queues'
|
|
8
8
|
require 'fake_sqs/responder'
|
9
9
|
require 'fake_sqs/server'
|
10
10
|
require 'fake_sqs/version'
|
11
|
-
require 'fake_sqs/
|
11
|
+
require 'fake_sqs/memory_database'
|
12
|
+
require 'fake_sqs/file_database'
|
12
13
|
|
13
14
|
module FakeSQS
|
14
15
|
|
16
|
+
def self.to_rack(options)
|
17
|
+
|
18
|
+
require 'fake_sqs/web_interface'
|
19
|
+
app = FakeSQS::WebInterface
|
20
|
+
|
21
|
+
if (log = options[:log])
|
22
|
+
$stdout.reopen(log, "w:utf-8")
|
23
|
+
$stderr.reopen(log, "w:utf-8")
|
24
|
+
app.enable :logging
|
25
|
+
end
|
26
|
+
|
27
|
+
if options[:verbose]
|
28
|
+
require 'fake_sqs/show_output'
|
29
|
+
app.use FakeSQS::ShowOutput
|
30
|
+
app.enable :logging
|
31
|
+
end
|
32
|
+
|
33
|
+
if options[:daemonize]
|
34
|
+
require 'fake_sqs/daemonize'
|
35
|
+
Daemonize.new(options).call
|
36
|
+
end
|
37
|
+
|
38
|
+
app.set :port, options[:port] if options[:port]
|
39
|
+
app.set :bind, options[:host] if options[:host]
|
40
|
+
app.set :server, options[:server] if options[:server]
|
41
|
+
server = FakeSQS.server(port: options[:port], host: options[:host])
|
42
|
+
app.set :api, FakeSQS.api(server: server, database: options[:database])
|
43
|
+
app
|
44
|
+
end
|
45
|
+
|
15
46
|
def self.server(options = {})
|
16
47
|
Server.new(options)
|
17
48
|
end
|
18
49
|
|
19
50
|
def self.api(options = {})
|
51
|
+
db = database_for(options.fetch(:database) { ":memory:" })
|
20
52
|
API.new(
|
21
53
|
server: options.fetch(:server),
|
22
|
-
queues: queues,
|
54
|
+
queues: queues(db),
|
23
55
|
responder: responder
|
24
56
|
)
|
25
57
|
end
|
26
58
|
|
27
|
-
def self.queues
|
28
|
-
Queues.new(queue_factory: queue_factory)
|
59
|
+
def self.queues(database)
|
60
|
+
Queues.new(queue_factory: queue_factory, database: database)
|
29
61
|
end
|
30
62
|
|
31
63
|
def self.responder
|
@@ -44,4 +76,12 @@ module FakeSQS
|
|
44
76
|
Queue
|
45
77
|
end
|
46
78
|
|
79
|
+
def self.database_for(name)
|
80
|
+
if name == ":memory:"
|
81
|
+
MemoryDatabase.new
|
82
|
+
else
|
83
|
+
FileDatabase.new(name)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
47
87
|
end
|
data/lib/fake_sqs/api.rb
CHANGED
@@ -16,7 +16,7 @@ module FakeSQS
|
|
16
16
|
|
17
17
|
class API
|
18
18
|
|
19
|
-
attr_reader :queues
|
19
|
+
attr_reader :queues, :options
|
20
20
|
|
21
21
|
def initialize(options = {})
|
22
22
|
@queues = options.fetch(:queues)
|
@@ -25,7 +25,10 @@ module FakeSQS
|
|
25
25
|
|
26
26
|
def call(action, *args)
|
27
27
|
if FakeSQS::Actions.const_defined?(action)
|
28
|
-
FakeSQS::Actions.const_get(action).new(
|
28
|
+
action = FakeSQS::Actions.const_get(action).new(options)
|
29
|
+
queues.transaction do
|
30
|
+
action.call(*args)
|
31
|
+
end
|
29
32
|
else
|
30
33
|
fail InvalidAction, "Unknown (or not yet implemented) action: #{action}"
|
31
34
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module FakeSQS
|
2
|
+
class Daemonize
|
3
|
+
|
4
|
+
attr_reader :pid
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@pid = options.fetch(:pid) {
|
8
|
+
warn "No PID file specified while daemonizing!"
|
9
|
+
exit 1
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
Process.daemon(true, true)
|
15
|
+
|
16
|
+
if File.exist?(pid)
|
17
|
+
existing_pid = File.open(pid, 'r').read.chomp.to_i
|
18
|
+
running = Process.getpgid(existing_pid) rescue false
|
19
|
+
if running
|
20
|
+
warn "Error, Process #{existing_pid} already running"
|
21
|
+
exit 1
|
22
|
+
else
|
23
|
+
warn "Cleaning up stale pid at #{pid}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
File.open(pid, 'w') { |f| f.write(Process.pid) }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "yaml/store"
|
2
|
+
|
3
|
+
module FakeSQS
|
4
|
+
class FileDatabase
|
5
|
+
|
6
|
+
attr_reader :filename
|
7
|
+
|
8
|
+
def initialize(filename)
|
9
|
+
@filename = filename
|
10
|
+
@queue_objects = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def load
|
14
|
+
transaction do
|
15
|
+
store["queues"] ||= {}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def transaction
|
20
|
+
store.transaction do
|
21
|
+
yield
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset
|
26
|
+
transaction do
|
27
|
+
store["queues"] = {}
|
28
|
+
end
|
29
|
+
@queue_objects = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def []=(key, value)
|
33
|
+
storage[key] = value.to_yaml
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](key)
|
37
|
+
value = storage[key]
|
38
|
+
if value
|
39
|
+
deserialize(key)
|
40
|
+
else
|
41
|
+
value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def each(&block)
|
46
|
+
storage.each do |key, value|
|
47
|
+
yield key, deserialize(key)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def select(&block)
|
52
|
+
new_list = storage.select do |key, value|
|
53
|
+
yield key, deserialize(key)
|
54
|
+
end
|
55
|
+
Hash[new_list.map { |key, value| [key, deserialize(key)] }]
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete(key)
|
59
|
+
storage.delete(key)
|
60
|
+
end
|
61
|
+
|
62
|
+
def values
|
63
|
+
storage.map { |key, value|
|
64
|
+
deserialize(key)
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def deserialize(key)
|
71
|
+
@queue_objects[key] ||= Queue.new(storage[key].merge(message_factory: Message))
|
72
|
+
end
|
73
|
+
|
74
|
+
def storage
|
75
|
+
store["queues"]
|
76
|
+
end
|
77
|
+
|
78
|
+
def store
|
79
|
+
@store ||= YAML::Store.new(filename)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module FakeSQS
|
4
|
+
class MemoryDatabase
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :@queues,
|
8
|
+
:[], :[]=, :delete, :each, :select, :values
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@in_transaction = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def load
|
15
|
+
@queues = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def transaction
|
19
|
+
if @in_transaction
|
20
|
+
raise "Already in transaction"
|
21
|
+
else
|
22
|
+
@in_transaction = true
|
23
|
+
begin
|
24
|
+
yield
|
25
|
+
ensure
|
26
|
+
@in_transaction = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
@queues = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/fake_sqs/message.rb
CHANGED
@@ -3,18 +3,20 @@ require 'securerandom'
|
|
3
3
|
module FakeSQS
|
4
4
|
class Message
|
5
5
|
|
6
|
-
attr_reader :body
|
6
|
+
attr_reader :body, :id, :md5
|
7
7
|
|
8
8
|
def initialize(options = {})
|
9
9
|
@body = options.fetch("MessageBody")
|
10
|
+
@id = options.fetch("Id") { SecureRandom.uuid }
|
11
|
+
@md5 = options.fetch("MD5") { Digest::MD5.hexdigest(@body) }
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def attributes
|
15
|
+
{
|
16
|
+
"MessageBody" => body,
|
17
|
+
"Id" => id,
|
18
|
+
"MD5" => md5,
|
19
|
+
}
|
18
20
|
end
|
19
21
|
|
20
22
|
end
|
data/lib/fake_sqs/queue.rb
CHANGED
@@ -6,22 +6,31 @@ module FakeSQS
|
|
6
6
|
|
7
7
|
class Queue
|
8
8
|
|
9
|
-
attr_reader :name, :messages, :message_factory, :messages_in_flight, :arn
|
9
|
+
attr_reader :name, :messages, :message_factory, :messages_in_flight, :arn, :queue_attributes
|
10
10
|
|
11
11
|
def initialize(options = {})
|
12
|
-
@name = options.fetch("QueueName")
|
13
12
|
@message_factory = options.fetch(:message_factory)
|
14
|
-
|
15
|
-
@
|
13
|
+
|
14
|
+
@name = options.fetch("QueueName")
|
15
|
+
@arn = options.fetch("Arn") { "arn:aws:sqs:us-east-1:#{SecureRandom.hex}:#{@name}" }
|
16
|
+
@queue_attributes = options.fetch("Attributes") { {} }
|
16
17
|
reset
|
17
18
|
end
|
18
19
|
|
20
|
+
def to_yaml
|
21
|
+
{
|
22
|
+
"QueueName" => name,
|
23
|
+
"Arn" => arn,
|
24
|
+
"Attributes" => queue_attributes,
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
19
28
|
def add_queue_attributes(attrs)
|
20
|
-
|
29
|
+
queue_attributes.merge!(attrs)
|
21
30
|
end
|
22
31
|
|
23
32
|
def attributes
|
24
|
-
|
33
|
+
queue_attributes.merge(
|
25
34
|
"QueueArn" => arn,
|
26
35
|
"ApproximateNumberOfMessages" => messages.size,
|
27
36
|
"ApproximateNumberOfMessagesNotVisible" => messages_in_flight.size,
|
data/lib/fake_sqs/queues.rb
CHANGED
@@ -5,25 +5,26 @@ module FakeSQS
|
|
5
5
|
|
6
6
|
class Queues
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :queue_factory, :database
|
9
9
|
|
10
10
|
def initialize(options = {})
|
11
11
|
@queue_factory = options.fetch(:queue_factory)
|
12
|
-
|
12
|
+
@database = options.fetch(:database)
|
13
|
+
@database.load
|
13
14
|
end
|
14
15
|
|
15
16
|
def create(name, options = {})
|
16
|
-
if
|
17
|
+
if database[name]
|
17
18
|
fail QueueNameExists, name
|
18
19
|
else
|
19
20
|
queue = queue_factory.new(options)
|
20
|
-
|
21
|
+
database[name] = queue
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def delete(name, options = {})
|
25
|
-
if
|
26
|
-
|
26
|
+
if database[name]
|
27
|
+
database.delete(name)
|
27
28
|
else
|
28
29
|
fail NonExistentQueue, name
|
29
30
|
end
|
@@ -31,26 +32,38 @@ module FakeSQS
|
|
31
32
|
|
32
33
|
def list(options = {})
|
33
34
|
if (prefix = options["QueueNamePrefix"])
|
34
|
-
|
35
|
+
database.select { |name, queue| name.start_with?(prefix) }.values
|
35
36
|
else
|
36
|
-
|
37
|
+
database.values
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
41
|
def get(name, options = {})
|
41
|
-
if
|
42
|
-
|
42
|
+
if (db = database[name])
|
43
|
+
db
|
43
44
|
else
|
44
45
|
fail NonExistentQueue, name
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
def transaction
|
50
|
+
database.transaction do
|
51
|
+
yield
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def save(queue)
|
56
|
+
database[queue.name] = queue
|
57
|
+
end
|
58
|
+
|
48
59
|
def reset
|
49
|
-
|
60
|
+
database.reset
|
50
61
|
end
|
51
62
|
|
52
63
|
def expire
|
53
|
-
|
64
|
+
transaction do
|
65
|
+
database.each { |name, queue| queue.expire }
|
66
|
+
end
|
54
67
|
end
|
55
68
|
|
56
69
|
end
|
@@ -23,7 +23,8 @@ module FakeSQS
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def start!
|
26
|
-
|
26
|
+
args = [ binfile, "-p", port.to_s, verbose, logging, "--database", database, { :out => out, :err => out } ].flatten.compact
|
27
|
+
@pid = Process.spawn(*args)
|
27
28
|
wait_until_up
|
28
29
|
end
|
29
30
|
|
@@ -61,6 +62,25 @@ module FakeSQS
|
|
61
62
|
options.fetch(key) { AWS.config.public_send(key) }
|
62
63
|
end
|
63
64
|
|
65
|
+
def database
|
66
|
+
options.fetch(:database)
|
67
|
+
end
|
68
|
+
|
69
|
+
def verbose
|
70
|
+
if debug?
|
71
|
+
"--verbose"
|
72
|
+
else
|
73
|
+
"--no-verbose"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def logging
|
78
|
+
if (file = ENV["SQS_LOG"] || options[:log])
|
79
|
+
[ "--log", file ]
|
80
|
+
else
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
end
|
64
84
|
|
65
85
|
def wait_until_up(deadline = Time.now + 2)
|
66
86
|
fail "FakeSQS didn't start in time" if Time.now > deadline
|
@@ -87,7 +107,7 @@ module FakeSQS
|
|
87
107
|
end
|
88
108
|
|
89
109
|
def debug?
|
90
|
-
ENV["DEBUG"].to_s == "true"
|
110
|
+
ENV["DEBUG"].to_s == "true" || options[:debug]
|
91
111
|
end
|
92
112
|
|
93
113
|
end
|
data/lib/fake_sqs/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -9,13 +9,15 @@ AWS.config(
|
|
9
9
|
:secret_access_key => "fake secret key",
|
10
10
|
)
|
11
11
|
|
12
|
-
|
12
|
+
db = ENV["SQS_DATABASE"] || ":memory:"
|
13
|
+
puts "\n\e[34mRunning specs with database \e[33m#{db}\e[0m"
|
14
|
+
$fake_sqs = FakeSQS::TestIntegration.new(database: db)
|
13
15
|
|
14
16
|
RSpec.configure do |config|
|
15
17
|
|
16
18
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
|
-
config.before(:suite) { $fake_sqs = FakeSQS::TestIntegration.new }
|
18
19
|
config.before(:each, :sqs) { $fake_sqs.start }
|
20
|
+
config.before(:each, :sqs) { $fake_sqs.reset }
|
19
21
|
config.after(:suite) { $fake_sqs.stop }
|
20
22
|
|
21
23
|
end
|
data/spec/unit/api_spec.rb
CHANGED
@@ -15,11 +15,13 @@ end
|
|
15
15
|
describe FakeSQS::API do
|
16
16
|
|
17
17
|
it "delegates actions to classes" do
|
18
|
-
|
18
|
+
queues = double :queues
|
19
|
+
allow(queues).to receive(:transaction).and_yield
|
20
|
+
api = FakeSQS::API.new(:queues => queues)
|
19
21
|
|
20
22
|
response = api.call("TheAction", {:foo => "bar"})
|
21
23
|
|
22
|
-
response[:options].should eq :queues =>
|
24
|
+
response[:options].should eq :queues => queues
|
23
25
|
response[:params].should eq :foo => "bar"
|
24
26
|
end
|
25
27
|
|
data/spec/unit/queues_spec.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'fake_sqs/queues'
|
2
|
+
require 'fake_sqs/memory_database'
|
2
3
|
|
3
4
|
describe FakeSQS::Queues do
|
4
5
|
|
6
|
+
let(:fake_database) { FakeSQS::MemoryDatabase.new }
|
5
7
|
let(:queue_factory) { double :queue_factory, :new => double }
|
6
|
-
subject(:queues) { FakeSQS::Queues.new(queue_factory: queue_factory) }
|
8
|
+
subject(:queues) { FakeSQS::Queues.new(queue_factory: queue_factory, database: fake_database) }
|
7
9
|
|
8
10
|
describe "#create" do
|
9
11
|
|
10
12
|
it "creates new queues" do
|
11
|
-
queues.should
|
13
|
+
queues.list.size.should eq 0
|
12
14
|
create_queue("test")
|
13
|
-
queues.should
|
15
|
+
queues.list.size.should eq 1
|
14
16
|
end
|
15
17
|
|
16
18
|
it "uses the queue factory" do
|
@@ -38,9 +40,9 @@ describe FakeSQS::Queues do
|
|
38
40
|
|
39
41
|
it "deletes an existing queue" do
|
40
42
|
create_queue("test")
|
41
|
-
queues.should
|
43
|
+
queues.list.size.should eq 1
|
42
44
|
queues.delete("test")
|
43
|
-
queues.should
|
45
|
+
queues.list.size.should eq 0
|
44
46
|
end
|
45
47
|
|
46
48
|
it "cannot delete an non-existing queue" do
|
@@ -62,7 +64,7 @@ describe FakeSQS::Queues do
|
|
62
64
|
it "can be filtered by prefix" do
|
63
65
|
queue1 = create_queue("test-1")
|
64
66
|
queue2 = create_queue("test-2")
|
65
|
-
|
67
|
+
_ = create_queue("other-3")
|
66
68
|
queues.list("QueueNamePrefix" => "test").should eq [ queue1, queue2 ]
|
67
69
|
end
|
68
70
|
|
@@ -88,9 +90,9 @@ describe FakeSQS::Queues do
|
|
88
90
|
it "clears all queues" do
|
89
91
|
create_queue("foo")
|
90
92
|
create_queue("bar")
|
91
|
-
queues.should
|
93
|
+
queues.list.size.should eq 2
|
92
94
|
queues.reset
|
93
|
-
queues.should
|
95
|
+
queues.list.size.should eq 0
|
94
96
|
end
|
95
97
|
|
96
98
|
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.
|
4
|
+
version: 0.0.10
|
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-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -167,8 +167,11 @@ files:
|
|
167
167
|
- lib/fake_sqs/actions/set_queue_attributes.rb
|
168
168
|
- lib/fake_sqs/api.rb
|
169
169
|
- lib/fake_sqs/catch_errors.rb
|
170
|
+
- lib/fake_sqs/daemonize.rb
|
170
171
|
- lib/fake_sqs/error_response.rb
|
171
172
|
- lib/fake_sqs/error_responses.yml
|
173
|
+
- lib/fake_sqs/file_database.rb
|
174
|
+
- lib/fake_sqs/memory_database.rb
|
172
175
|
- lib/fake_sqs/message.rb
|
173
176
|
- lib/fake_sqs/queue.rb
|
174
177
|
- lib/fake_sqs/queue_factory.rb
|