gitlab-org--gitlab-foss/spec/lib/gitlab/tcp_checker_spec.rb
Nick Thomas ab4fa64308
Add a gitlab:tcp_check rake task
This allows us to avoid relying on telnet / netcat being installed
2017-12-13 15:53:32 +00:00

32 lines
592 B
Ruby

require 'spec_helper'
describe Gitlab::TcpChecker do
before do
@server = TCPServer.new('localhost', 0)
_, @port, _, @ip = @server.addr
end
after do
@server.close
end
subject(:checker) { described_class.new(@ip, @port) }
describe '#check' do
subject { checker.check }
it 'can connect to an open port' do
is_expected.to be_truthy
expect(checker.error).to be_nil
end
it 'fails to connect to a closed port' do
@server.close
is_expected.to be_falsy
expect(checker.error).to be_a(Errno::ECONNREFUSED)
end
end
end