spec/inputs/rabbitmq_spec.rb in logstash-input-rabbitmq-3.1.1 vs spec/inputs/rabbitmq_spec.rb in logstash-input-rabbitmq-3.1.2

- old
+ new

@@ -28,10 +28,11 @@ let(:channel) { double("Channel") } let(:exchange) { double("Exchange") } let(:channel) { double("Channel") } let(:queue) { double("queue") } + # Doing this in a before block doesn't give us enough control over scope before do allow(instance).to receive(:connect!).and_call_original allow(::MarchHare).to receive(:connect).and_return(connection) allow(connection).to receive(:create_channel).and_return(channel) allow(connection).to receive(:on_blocked) @@ -40,30 +41,57 @@ allow(channel).to receive(:queue).and_return(queue) allow(channel).to receive(:prefetch=) allow(queue).to receive(:build_consumer).with(:block => true) allow(queue).to receive(:subscribe_with).with(any_args) - - instance.register + allow(queue).to receive(:bind).with(any_args) end it "should default the codec to JSON" do expect(instance.codec).to be_a(LogStash::Codecs::JSON) end describe "#connect!" do subject { hare_info } - it "should set the queue correctly" do - expect(subject.queue).to eql(queue) - end + context "without an exchange declared" do + before do + instance.register + end - it "should set the prefetch value correctly" do - expect(channel).to have_received(:prefetch=).with(123) + it "should set the queue correctly" do + expect(subject.queue).to eql(queue) + end + + it "should set the prefetch value correctly" do + expect(channel).to have_received(:prefetch=).with(123) + end end context "with an exchange declared" do - let(:instance) { rabbitmq_settings.merge("exchange" => "myexchange", "exchange_type" => "fanout") } + let(:exchange) { double("exchange") } + let(:key) { double("routing key") } + let(:rabbitmq_settings) { super.merge("exchange" => exchange, "key" => key) } + + it "should bind to the exchange" do + instance.register + expect(queue).to have_received(:bind).with(exchange, :routing_key => key) + end + + context "but not immediately available" do + before do + i = 0 + allow(queue).to receive(:bind).with(any_args) do + i += 1 + raise "foo" if i == 1 + end + end + + it "should reconnect" do + instance.register + expect(queue).to have_received(:bind).with(any_args).twice() + end + end end end end end \ No newline at end of file