mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Initial support for mocking delete_message.
I need to investigate the actual exceptions in those two cases.
This commit is contained in:
parent
625ca8e255
commit
7c5775be32
4 changed files with 38 additions and 1 deletions
|
@ -143,6 +143,13 @@ module Fog
|
||||||
Time.now.to_i - @created
|
Time.now.to_i - @created
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return true if this message has been claimed.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
def claimed?
|
||||||
|
! @claimant_id.nil?
|
||||||
|
end
|
||||||
|
|
||||||
# Convert this message to a GET payload.
|
# Convert this message to a GET payload.
|
||||||
#
|
#
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
|
|
|
@ -38,6 +38,8 @@ module Fog
|
||||||
queue = data[queue_name]
|
queue = data[queue_name]
|
||||||
raise NotFound.new unless queue
|
raise NotFound.new unless queue
|
||||||
|
|
||||||
|
raise BadRequest.new if body.nil? || body.empty?
|
||||||
|
|
||||||
message = queue.add_message(client_id, body, ttl)
|
message = queue.add_message(client_id, body, ttl)
|
||||||
|
|
||||||
# FIXME: refactor /v1/queues out to an inherited constant
|
# FIXME: refactor /v1/queues out to an inherited constant
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
module Fog
|
module Fog
|
||||||
module Rackspace
|
module Rackspace
|
||||||
class Queues
|
class Queues
|
||||||
|
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# This operation immediately deletes the specified message.
|
# This operation immediately deletes the specified message.
|
||||||
|
@ -26,7 +27,34 @@ module Fog
|
||||||
:query => query
|
:query => query
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def delete_message(queue_name, message_id, options = {})
|
||||||
|
queue = data[queue_name]
|
||||||
|
raise NotFound.new unless queue
|
||||||
|
|
||||||
|
claim_id = options[:claim_id]
|
||||||
|
|
||||||
|
message = queue.messages.detect { |m| m.id == message_id }
|
||||||
|
|
||||||
|
if message.claimed?
|
||||||
|
unless message.claimant_id == claim_id
|
||||||
|
# Exception
|
||||||
|
end
|
||||||
|
else
|
||||||
|
unless claim_id
|
||||||
|
# Exception
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 204
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,7 +53,7 @@ module Fog
|
||||||
next_marker = marker + limit + 1
|
next_marker = marker + limit + 1
|
||||||
messages = queue.messages[marker...next_marker]
|
messages = queue.messages[marker...next_marker]
|
||||||
messages.reject! { |m| m.producer_id == client_id } unless echo
|
messages.reject! { |m| m.producer_id == client_id } unless echo
|
||||||
messages.select! { |m| m.claimant_id.nil? } unless include_claimed
|
messages.reject! { |m| m.claimed? } unless include_claimed
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
if queue.messages.empty?
|
if queue.messages.empty?
|
||||||
|
|
Loading…
Reference in a new issue