Class: AwsSqsFauxClient

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_support/aws_sqs_faux_client.rb

Overview

See Also:

  • [DerivativeRodeo[DerivativeRodeo::StorageAdapters[DerivativeRodeo::StorageAdapters::SqsAdapter]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_url: nil) ⇒ AwsSqsFauxClient

Returns a new instance of AwsSqsFauxClient.



9
10
11
12
# File 'lib/spec_support/aws_sqs_faux_client.rb', line 9

def initialize(queue_url: nil)
  @queue_url = queue_url || 'https://sqs.us-west-2.amazonaws.com/5555555555/fake'
  @storage = {}
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



13
14
15
# File 'lib/spec_support/aws_sqs_faux_client.rb', line 13

def storage
  @storage
end

Instance Method Details

#get_queue_urlObject



33
34
35
# File 'lib/spec_support/aws_sqs_faux_client.rb', line 33

def get_queue_url(*)
  OpenStruct.new(queue_url: @queue_url)
end

#receive_message(arg_hash) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/spec_support/aws_sqs_faux_client.rb', line 25

def receive_message(arg_hash)
  output = []
  args_hash[:mx_number_of_messages].times do
    value = @storage[arg_hash[:queue_url]]&.pop
    output << value if value
  end
end

#send_message(arg_hash) ⇒ Object



15
16
17
18
# File 'lib/spec_support/aws_sqs_faux_client.rb', line 15

def send_message(arg_hash)
  @storage[arg_hash[:queue_url]] ||= []
  @storage[arg_hash[:queue_url]] << arg_hash[:message_body]
end

#send_message_batch(arg_hash) ⇒ Object



20
21
22
23
# File 'lib/spec_support/aws_sqs_faux_client.rb', line 20

def send_message_batch(arg_hash)
  @storage[arg_hash[:queue_url]] ||= []
  @storage[arg_hash[:queue_url]] += arg_hash[:entries]
end