spec/elasticsearch/transport/sniffer_spec.rb in elasticsearch-transport-7.8.1 vs spec/elasticsearch/transport/sniffer_spec.rb in elasticsearch-transport-7.9.0.pre

- old
+ new

@@ -16,11 +16,10 @@ # under the License. require 'spec_helper' describe Elasticsearch::Transport::Transport::Sniffer do - let(:transport) do double('transport').tap do |t| allow(t).to receive(:perform_request).and_return(response) allow(t).to receive(:options).and_return(sniffer_timeout: 2) end @@ -43,22 +42,20 @@ let(:publish_address) do '127.0.0.1:9250' end describe '#initialize' do - it 'has a transport instance' do expect(sniffer.transport).to be(transport) end it 'inherits the sniffer timeout from the transport object' do expect(sniffer.timeout).to eq(2) end end describe '#timeout' do - let(:sniffer) do described_class.new(double('transport', options: {})) end before do @@ -69,17 +66,15 @@ expect(sniffer.timeout).to eq(3) end end describe '#hosts' do - let(:hosts) do sniffer.hosts end context 'when the entire response is parsed' do - let(:raw_response) do { "cluster_name" => "elasticsearch_test", "nodes" => { "N1" => { @@ -140,22 +135,20 @@ expect(sniffer.hosts[0][:attributes]).to eq('testattr' => 'test') end end context 'when the transport protocol does not match' do - let(:raw_response) do { 'nodes' => { 'n1' => { 'foo' => { 'publish_address' => '127.0.0.1:9250' } } } } end it 'does not parse the addresses' do expect(hosts).to eq([]) end end context 'when a list of nodes is returned' do - let(:raw_response) do { 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } }, 'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } } end @@ -173,11 +166,10 @@ expect(hosts[1][:port]).to eq('9251') end end context 'when the host and port are an ip address and port' do - it 'parses the response' do expect(hosts.size).to eq(1) end it 'correctly parses the host' do @@ -188,11 +180,10 @@ expect(hosts[0][:port]).to eq('9250') end end context 'when the host and port are a hostname and port' do - let(:publish_address) do 'testhost1.com:9250' end let(:hosts) do @@ -211,11 +202,10 @@ expect(hosts[0][:port]).to eq('9250') end end context 'when the host and port are in the format: hostname/ip:port' do - let(:publish_address) do 'example.com/127.0.0.1:9250' end it 'parses the response' do @@ -229,11 +219,10 @@ it 'correctly parses the port' do expect(hosts[0][:port]).to eq('9250') end context 'when the address is IPv6' do - let(:publish_address) do 'example.com/[::1]:9250' end it 'parses the response' do @@ -249,11 +238,10 @@ end end end context 'when the address is IPv6' do - let(:publish_address) do '[::1]:9250' end it 'parses the response' do @@ -268,10 +256,9 @@ expect(hosts[0][:port]).to eq('9250') end end context 'when the transport has :randomize_hosts option' do - let(:raw_response) do { 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } }, 'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } } end