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
|
||||
end
|
||||
|
||||
# Return true if this message has been claimed.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def claimed?
|
||||
! @claimant_id.nil?
|
||||
end
|
||||
|
||||
# Convert this message to a GET payload.
|
||||
#
|
||||
# @return [Hash]
|
||||
|
|
|
@ -38,6 +38,8 @@ module Fog
|
|||
queue = data[queue_name]
|
||||
raise NotFound.new unless queue
|
||||
|
||||
raise BadRequest.new if body.nil? || body.empty?
|
||||
|
||||
message = queue.add_message(client_id, body, ttl)
|
||||
|
||||
# FIXME: refactor /v1/queues out to an inherited constant
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class Queues
|
||||
|
||||
class Real
|
||||
|
||||
# This operation immediately deletes the specified message.
|
||||
|
@ -26,7 +27,34 @@ module Fog
|
|||
:query => query
|
||||
)
|
||||
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
|
||||
|
|
|
@ -53,7 +53,7 @@ module Fog
|
|||
next_marker = marker + limit + 1
|
||||
messages = queue.messages[marker...next_marker]
|
||||
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
|
||||
if queue.messages.empty?
|
||||
|
|
Loading…
Reference in a new issue