require 'spec_helper' describe Roqua::Healthy::A19::Fetcher do let(:client) { Roqua::Healthy::Client.new } subject { Roqua::Healthy::A19::Fetcher.new("123", client) } it 'succeeds when upstream returns XML' do stub_mirth_response("") expect { subject.fetch }.not_to raise_error end it "raises when upstream does not return HTTP 200" do stub_mirth_response "Request not successful", 500 expect { subject.fetch }.to raise_exception end it 'raises when upstream responds with illegal XML' do stub_mirth_response "Jan & Piet" expect { subject.fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse) stub_mirth_response "Jan" expect { subject.fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse) end it "raises upstream is returning 'Timeout waiting for ACK' messages" do stub_mirth_response "Timeout waiting for ACK", 500 expect { subject.fetch }.to raise_exception(Roqua::Healthy::Timeout) end it "raises upstream is returning 'connection timeout' messages" do stub_mirth_response "Unable to connect to destination\tSocketTimeoutException\tconnect timed out", 500 expect { subject.fetch }.to raise_exception(Roqua::Healthy::Timeout) end it "raises upstream is returning 'connection refused' messages" do stub_mirth_response "Unable to connect to destination\tConnectException\tConnection refused", 500 expect { subject.fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused) end it "raises when upstream does not accept connections" do stub_mirth.to_raise Errno::ECONNREFUSED expect { subject.fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused) end it 'raises when upstream is unreachable' do stub_mirth.to_raise Errno::EHOSTUNREACH expect { subject.fetch }.to raise_exception(Roqua::Healthy::HostUnreachable) end it "raises when upstream is timing out" do stub_mirth.to_timeout expect { subject.fetch }.to raise_exception(Roqua::Healthy::Timeout) stub_mirth.to_raise Errno::ETIMEDOUT expect { subject.fetch }.to raise_exception(Roqua::Healthy::Timeout) end it 'saves the client' do expect(subject.client).to eq client end describe '#remote_url' do let(:fetcher) { Roqua::Healthy::A19::Fetcher.new("123", client) } it 'uses the client config if available' do expect(client).to receive(:a19_endpoint).and_call_original fetcher.send(:remote_url) end end end