diff options
author | Nick Thomas <nick@gitlab.com> | 2017-12-06 12:39:25 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-12-13 18:53:32 +0300 |
commit | ab4fa64308176cc069e6a731d35a53c886af805e (patch) | |
tree | 09d0c5d8a1a50abe3aa1aef418407b3379d3d2ec /spec/lib/gitlab/tcp_checker_spec.rb | |
parent | 8ff63039f1ee5f6e31a8b910e323977e7de3c634 (diff) |
Add a gitlab:tcp_check rake task
This allows us to avoid relying on telnet / netcat being installed
Diffstat (limited to 'spec/lib/gitlab/tcp_checker_spec.rb')
-rw-r--r-- | spec/lib/gitlab/tcp_checker_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/lib/gitlab/tcp_checker_spec.rb b/spec/lib/gitlab/tcp_checker_spec.rb new file mode 100644 index 00000000000..4acf0334496 --- /dev/null +++ b/spec/lib/gitlab/tcp_checker_spec.rb @@ -0,0 +1,32 @@ +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 |