Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
feat: add test to poller success
Browse files Browse the repository at this point in the history
  • Loading branch information
eHattori committed Apr 19, 2022
1 parent 374fa3e commit 7f68344
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pipefy_message/providers/aws_broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Providers
class AwsBroker < Broker
def initialize(queue_name, opts={})
@config = build_options(opts)
# require 'pry'; binding.pry
Aws.config.update(@config)
@sqs = Aws::SQS::Client.new

Expand Down
45 changes: 45 additions & 0 deletions spec/providers/aws_broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@
before do
stub_const("ENV", ENV.to_hash.merge("AWS_CLI_STUB_RESPONSE" => "true"))
end

describe "#poller" do
mocked_poller = nil

before do
mocked_message = { message_id: "44c44782-fee1-6784-d614-43b73c0bda8d",
receipt_handle: "2312dasdas1231221312321adsads",
body: "{\"Message\": {\"foo\": \"bar\"}}" }
mocked_poller = Aws::SQS::QueuePoller.new("http://localhost:4566/000000000000/my_queue",
{ skip_delete: true })
mocked_poller.before_request { |stats| throw :stop_polling if stats.received_message_count > 0 }

mocked_element = Aws::SQS::Types::Message.new(mocked_message)
mocked_list = Aws::Xml::DefaultList.new
mocked_list.append(mocked_element)
mocked_poller.client.stub_responses(:receive_message, messages: mocked_list)
end
it "should consume message" do
worker = PipefyMessage::Providers::AwsBroker.new("my_queue")
worker.instance_variable_set(:@poller, mocked_poller)

result = nil
expected_result = { "Message" => { "foo" => "bar" } }
worker.poller do |message|
result = message
end
expect(result).to eq expected_result
end
end

describe "should raise Errors" do
it "QueueNonExistError" do
allow_any_instance_of(Aws::SQS::Client)
Expand All @@ -24,6 +54,21 @@
end.to raise_error(PipefyMessage::Providers::Errors::ResourceError,
/The specified queue my_queue does not exist for this wsdl version/)
end
it "NetworkingError" do
allow_any_instance_of(Aws::SQS::Client)
.to receive(:get_queue_url)
.with({ queue_name: "my_queue" })
.and_raise(
Seahorse::Client::NetworkingError.new(
Errno::ECONNREFUSED.new(""),
"Failed to open TCP connection"
)
)

expect do
PipefyMessage::Providers::AwsBroker.new("my_queue")
end.to raise_error(PipefyMessage::Providers::Errors::ResourceError)
end
end
end
end

0 comments on commit 7f68344

Please sign in to comment.