fake_sqs 0.4.0 → 0.4.1

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: '063098d4ed74f09793d0bde5c6fb857256893bec'
4
- data.tar.gz: 7ae4304c0a2d4d2a55c579730641d13a86a0656b
3
+ metadata.gz: fc20ac34a0c6c8147c3af9692169ae145b7d2e9c
4
+ data.tar.gz: 2964e38cee5d603014a322e514cfa63989cf66a8
5
5
  SHA512:
6
- metadata.gz: 9b19a220db375f3b500ede5450c91b51d9a4023e19253f0fe3f842867c25335d0a9977b176ad1589bd0d24f5d1e62d597ea70e9a584b624008f27ba246a48ddf
7
- data.tar.gz: 5ef566736e06d3ebe61e43e7c2b680df2e59a008a253a0b71776ed534bb8921bea6affa5460da71a87b022f563df96be65b6c957b1ddcf0df8867bfd76376892
6
+ metadata.gz: 8bafd8828d1f473c9a881d4c00a07f9e447bc6153869adbad17ae2d60fb97f5c248558122830ed66635f48b563c5eebb7fd4ce37eba7bc66ea95b6036e8fe6c0
7
+ data.tar.gz: e1ec826376dfb67c9f1f910903bf6852e66b73f2821014fe11e773aed50cea51251eed804d69ca99ea24cac3c8515786cf0932edc4cb0187314d7d0e2cb069fa
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
17
17
  gem.require_paths = ["lib"]
18
18
  gem.license = "MIT"
19
19
 
20
+
21
+ gem.add_dependency "rack", "~> 2.0"
20
22
  gem.add_dependency "sinatra", "~> 2.0"
21
23
  gem.add_dependency "builder", "~> 3.2"
22
24
 
@@ -6,13 +6,14 @@ module FakeSQS
6
6
  @server = options.fetch(:server)
7
7
  @queues = options.fetch(:queues)
8
8
  @responder = options.fetch(:responder)
9
+ @request = options.fetch(:request)
9
10
  end
10
11
 
11
12
  def call(params)
12
13
  name = params.fetch("QueueName")
13
14
  queue = @queues.create(name, params)
14
15
  @responder.call :CreateQueue do |xml|
15
- xml.QueueUrl @server.url_for(queue.name)
16
+ xml.QueueUrl @server.url_for(queue.name, {:host => @request.host, :port => @request.port})
16
17
  end
17
18
  end
18
19
 
@@ -6,13 +6,14 @@ module FakeSQS
6
6
  @server = options.fetch(:server)
7
7
  @queues = options.fetch(:queues)
8
8
  @responder = options.fetch(:responder)
9
+ @request = options.fetch(:request)
9
10
  end
10
11
 
11
12
  def call(params)
12
13
  name = params.fetch("QueueName")
13
14
  queue = @queues.get(name, params)
14
15
  @responder.call :GetQueueUrl do |xml|
15
- xml.QueueUrl @server.url_for(queue.name)
16
+ xml.QueueUrl @server.url_for(queue.name, {:host => @request.host, :port => @request.port})
16
17
  end
17
18
  end
18
19
 
@@ -6,13 +6,14 @@ module FakeSQS
6
6
  @server = options.fetch(:server)
7
7
  @queues = options.fetch(:queues)
8
8
  @responder = options.fetch(:responder)
9
+ @request = options.fetch(:request)
9
10
  end
10
11
 
11
12
  def call(params)
12
13
  found = @queues.list(params)
13
14
  @responder.call :ListQueues do |xml|
14
15
  found.each do |queue|
15
- xml.QueueUrl @server.url_for(queue.name)
16
+ xml.QueueUrl @server.url_for(queue.name, {:host => @request.host, :port => @request.port})
16
17
  end
17
18
  end
18
19
  end
@@ -34,9 +34,9 @@ module FakeSQS
34
34
  end
35
35
  end
36
36
 
37
- def call(action, *args)
37
+ def call(action, request, *args)
38
38
  if FakeSQS::Actions.const_defined?(action)
39
- action = FakeSQS::Actions.const_get(action).new(options)
39
+ action = FakeSQS::Actions.const_get(action).new(options.merge({:request => request}))
40
40
  queues.transaction do
41
41
  action.call(*args)
42
42
  end
@@ -16,7 +16,7 @@ module FakeSQS
16
16
  end
17
17
 
18
18
  def body
19
- xml = Builder::XmlMarkup.new(:index => 4)
19
+ xml = Builder::XmlMarkup.new()
20
20
  xml.ErrorResponse do
21
21
  xml.Error do
22
22
  xml.Type type
@@ -24,7 +24,6 @@ NoSuchVersion: 400
24
24
  NonExistentQueue: 400
25
25
  NotAuthorizedToUseVersion: 401
26
26
  QueueDeletedRecently: 400
27
- QueueNameExists: 400
28
27
  ReadCountOutOfRange: 400
29
28
  ReceiptHandleIsInvalid: 400
30
29
  RequestExpired: 400
@@ -1,3 +1,4 @@
1
+ require 'monitor'
1
2
  require 'securerandom'
2
3
  require 'fake_sqs/collection_view'
3
4
  require 'json'
@@ -1,6 +1,5 @@
1
1
  module FakeSQS
2
2
 
3
- QueueNameExists = Class.new(RuntimeError)
4
3
  NonExistentQueue = Class.new(RuntimeError)
5
4
 
6
5
  class Queues
@@ -5,7 +5,7 @@ module FakeSQS
5
5
  class Responder
6
6
 
7
7
  def call(name, &block)
8
- xml = Builder::XmlMarkup.new(:indent => 4)
8
+ xml = Builder::XmlMarkup.new()
9
9
  xml.tag! "#{name}Response" do
10
10
  if block
11
11
  xml.tag! "#{name}Result" do
@@ -8,7 +8,10 @@ module FakeSQS
8
8
  @port = options.fetch(:port)
9
9
  end
10
10
 
11
- def url_for(queue_id)
11
+ def url_for(queue_id, options = {})
12
+ host = options[:host] || @host
13
+ port = options[:port] || @port
14
+
12
15
  "http://#{host}:#{port}/#{queue_id}"
13
16
  end
14
17
 
@@ -25,7 +25,7 @@ module FakeSQS
25
25
  def start!
26
26
  args = [ binfile, "-p", port.to_s, verbose, logging, "--database", database, { :out => out, :err => out } ].flatten.compact
27
27
  @pid = Process.spawn(*args)
28
- wait_until_up
28
+ wait_until_up(Time.now + start_timeout)
29
29
  end
30
30
 
31
31
  def stop
@@ -70,6 +70,10 @@ module FakeSQS
70
70
  options.fetch(:database)
71
71
  end
72
72
 
73
+ def start_timeout
74
+ options[:start_timeout] || 2
75
+ end
76
+
73
77
  def verbose
74
78
  if debug?
75
79
  "--verbose"
@@ -86,10 +90,10 @@ module FakeSQS
86
90
  end
87
91
  end
88
92
 
89
- def wait_until_up(deadline = Time.now + 2)
93
+ def wait_until_up(deadline)
90
94
  fail "FakeSQS didn't start in time" if Time.now > deadline
91
95
  unless up?
92
- sleep 0.01
96
+ sleep 0.1
93
97
  wait_until_up(deadline)
94
98
  end
95
99
  end
@@ -1,3 +1,3 @@
1
1
  module FakeSQS
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -36,17 +36,16 @@ module FakeSQS
36
36
  end
37
37
 
38
38
  handle "/", [:get, :post] do
39
- params['logger'] = logger
40
39
  if params['QueueUrl']
41
40
  queue = URI.parse(params['QueueUrl']).path.gsub(/\//, '')
42
- return settings.api.call(action, queue, params) unless queue.empty?
41
+ return settings.api.call(action, request, queue, params) unless queue.empty?
43
42
  end
44
43
 
45
- settings.api.call(action, params)
44
+ settings.api.call(action, request, params)
46
45
  end
47
46
 
48
47
  handle "/:queue", [:get, :post] do |queue|
49
- settings.api.call(action, queue, params)
48
+ settings.api.call(action, request, queue, params)
50
49
  end
51
50
  end
52
51
  end
@@ -11,8 +11,9 @@ puts "\n\e[34mRunning specs with database \e[33m#{db}\e[0m"
11
11
 
12
12
  $fake_sqs = FakeSQS::TestIntegration.new(
13
13
  database: db,
14
- sqs_endpoint: "localhost",
14
+ sqs_endpoint: "0.0.0.0",
15
15
  sqs_port: 4568,
16
+ start_timeout: 2,
16
17
  )
17
18
 
18
19
  RSpec.configure do |config|
@@ -19,9 +19,9 @@ RSpec.describe FakeSQS::API do
19
19
  allow(queues).to receive(:transaction).and_yield
20
20
  api = FakeSQS::API.new(:queues => queues)
21
21
 
22
- response = api.call("TheAction", {:foo => "bar"})
22
+ response = api.call("TheAction", {}, {:foo => "bar"})
23
23
 
24
- expect(response[:options]).to eq :queues => queues
24
+ expect(response[:options]).to eq :queues => queues, :request => {}
25
25
  expect(response[:params]).to eq :foo => "bar"
26
26
  end
27
27
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_sqs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - iain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-21 00:00:00.000000000 Z
11
+ date: 2017-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: sinatra
15
29
  requirement: !ruby/object:Gem::Requirement