(maint) Update spec tests for timeout change.

This commit is contained in:
isaac-hammes 2023-03-02 11:50:06 -08:00
parent 5e1891b990
commit 0fb77b917d

View file

@ -1399,44 +1399,44 @@ EOT
end
it 'opens socket with defaults' do
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: 5}).and_return(socket)
expect(subject.open_socket(hostname)).to eq(nil)
end
it 'yields the socket if a block is given' do
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: nil}).and_return(socket)
expect{ |socket| subject.open_socket(hostname,nil,nil,default_socket,&socket) }.to yield_control.exactly(1).times
end
it 'closes the opened socket' do
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: 5}).and_return(socket)
expect(socket).to receive(:close)
expect(subject.open_socket(hostname)).to eq(nil)
end
it 'opens a specific socket' do
expect(TCPSocket).to receive(:new).with(hostname,80).and_return(socket)
expect(TCPSocket).to receive(:new).with(hostname,80,{connect_timeout: nil}).and_return(socket)
expect(subject.open_socket(hostname,nil,nil,80)).to eq(nil)
end
it 'uses a specific domain with the hostname' do
expect(TCPSocket).to receive(:new).with("#{hostname}.#{domain}",default_socket).and_return(socket)
expect(TCPSocket).to receive(:new).with("#{hostname}.#{domain}",default_socket,{connect_timeout: 5}).and_return(socket)
expect(subject.open_socket(hostname,domain)).to eq(nil)
end
it 'raises error if host is not resolvable' do
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_raise(SocketError,'getaddrinfo: No such host is known')
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: 1}).and_raise(SocketError,'getaddrinfo: No such host is known')
expect { subject.open_socket(hostname,nil,1) }.to raise_error(SocketError)
end
it 'raises error if socket is not listening' do
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_raise(SocketError,'No connection could be made because the target machine actively refused it')
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: 1}).and_raise(SocketError,'No connection could be made because the target machine actively refused it')
expect { subject.open_socket(hostname,nil,1) }.to raise_error(SocketError)
end