igp 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +56 -0
- data/.rubocop.yml +35 -0
- data/.rubocop_todo.yml +86 -0
- data/Gemfile +2 -10
- data/Guardfile +16 -0
- data/Rakefile +11 -42
- data/bin/igp +3 -4
- data/igp.gemspec +28 -73
- data/lib/igp/base.rb +19 -22
- data/lib/igp/shell.rb +36 -34
- data/lib/igp/version.rb +1 -1
- data/lib/igp.rb +0 -1
- data/spec/base_spec.rb +42 -42
- data/spec/format_spec.rb +24 -26
- data/spec/shell_spec.rb +93 -94
- data/spec/spec_helper.rb +4 -4
- metadata +150 -96
- data/Gemfile.lock +0 -34
- data/init.rb +0 -1
data/spec/base_spec.rb
CHANGED
@@ -2,65 +2,65 @@ require 'spec_helper'
|
|
2
2
|
require 'getoptions'
|
3
3
|
|
4
4
|
describe Igp::Base do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
subject.ping_handler.should be_nil
|
5
|
+
describe 'base initialization without options' do
|
6
|
+
it 'should not set ping_handler' do
|
7
|
+
expect(subject.ping_handler).to be_nil
|
9
8
|
end
|
10
|
-
it
|
11
|
-
subject.limit.
|
9
|
+
it 'should not set limit' do
|
10
|
+
expect(subject.limit).to be_nil
|
12
11
|
end
|
13
|
-
it
|
14
|
-
subject.interval.
|
12
|
+
it 'should default interval to 5 sec' do
|
13
|
+
expect(subject.interval).to eql(5)
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
options = { :
|
21
|
-
base = Igp::Base.new(options)
|
22
|
-
base.ping_handler.should be_a(Net::Ping::External)
|
23
|
-
end
|
24
|
-
it "should be Net::Ping::UDP for :tcp" do
|
25
|
-
options = { :type => :udp, :host => 'localhost', :port => 22}
|
26
|
-
base = Igp::Base.new(options)
|
27
|
-
base.ping_handler.should be_a(Net::Ping::UDP)
|
28
|
-
end
|
29
|
-
it "should be Net::Ping::TCP for :tcp" do
|
30
|
-
options = { :type => :tcp, :host => 'localhost', :port => 22}
|
16
|
+
|
17
|
+
describe 'ping_handler configuration' do
|
18
|
+
it 'should be Net::Ping::External for :icmp' do
|
19
|
+
options = { type: :icmp, host: 'localhost', port: nil }
|
31
20
|
base = Igp::Base.new(options)
|
32
|
-
base.ping_handler.
|
21
|
+
expect(base.ping_handler).to be_a(Net::Ping::External)
|
33
22
|
end
|
34
|
-
it
|
35
|
-
options = { :
|
23
|
+
it 'should be Net::Ping::UDP for :tcp' do
|
24
|
+
options = { type: :udp, host: 'localhost', port: 22 }
|
36
25
|
base = Igp::Base.new(options)
|
37
|
-
base.ping_handler.
|
26
|
+
expect(base.ping_handler).to be_a(Net::Ping::UDP)
|
38
27
|
end
|
39
|
-
it
|
40
|
-
options = { :
|
28
|
+
it 'should be Net::Ping::TCP for :tcp' do
|
29
|
+
options = { type: :tcp, host: 'localhost', port: 22 }
|
41
30
|
base = Igp::Base.new(options)
|
42
|
-
base.ping_handler.
|
31
|
+
expect(base.ping_handler).to be_a(Net::Ping::TCP)
|
43
32
|
end
|
44
|
-
it
|
45
|
-
options = { :
|
33
|
+
it 'should be Net::Ping::HTTP for :http' do
|
34
|
+
options = { type: :http, url: 'http://localhost' }
|
46
35
|
base = Igp::Base.new(options)
|
47
|
-
base.ping_handler.
|
36
|
+
expect(base.ping_handler).to be_a(Net::Ping::HTTP)
|
48
37
|
end
|
49
|
-
it
|
50
|
-
options = { :
|
38
|
+
it 'should be Net::Ping::HTTP for :https' do
|
39
|
+
options = { type: :https, url: 'https://localhost' }
|
51
40
|
base = Igp::Base.new(options)
|
52
|
-
base.ping_handler.
|
41
|
+
expect(base.ping_handler).to be_a(Net::Ping::HTTP)
|
53
42
|
end
|
43
|
+
# TODO: LDAP was retired from net-ping. to add back in one way or another
|
44
|
+
# it 'should be Net::Ping::LDAP for :ldap' do
|
45
|
+
# options = { type: :ldap, url: 'ldap://localhost' }
|
46
|
+
# base = Igp::Base.new(options)
|
47
|
+
# expect(base.ping_handler).to be_a(Net::Ping::LDAP)
|
48
|
+
# end
|
49
|
+
# it 'should be Net::Ping::LDAP for :ldaps' do
|
50
|
+
# options = { type: :ldaps, url: 'ldaps://localhost' }
|
51
|
+
# base = Igp::Base.new(options)
|
52
|
+
# expect(base.ping_handler).to be_a(Net::Ping::LDAP)
|
53
|
+
# end
|
54
54
|
end
|
55
55
|
|
56
|
-
describe
|
56
|
+
describe '#run' do
|
57
57
|
before do
|
58
|
-
@good = Igp::Base.new({ :
|
58
|
+
@good = Igp::Base.new({ type: :icmp, host: 'localhost', port: nil, limit: 1 })
|
59
59
|
end
|
60
|
-
it
|
61
|
-
@good.formatter.
|
62
|
-
@good.formatter.
|
63
|
-
capture(:stdout
|
60
|
+
it 'should print header and log a ping result' do
|
61
|
+
expect(@good.formatter).to receive(:header)
|
62
|
+
expect(@good.formatter).to receive(:log)
|
63
|
+
capture(:stdout, :stderr) { @good.run }
|
64
64
|
end
|
65
65
|
end
|
66
|
-
end
|
66
|
+
end
|
data/spec/format_spec.rb
CHANGED
@@ -2,47 +2,45 @@ require 'spec_helper'
|
|
2
2
|
require 'getoptions'
|
3
3
|
|
4
4
|
describe Igp::Base::Format do
|
5
|
-
|
6
5
|
describe '#duration' do
|
7
|
-
it
|
8
|
-
subject.duration(nil).
|
6
|
+
it 'should return nil for nil duration' do
|
7
|
+
expect(subject.duration(nil)).to be_nil
|
9
8
|
end
|
10
|
-
it
|
9
|
+
it 'should return string to 6 decimal places for non-nil duration' do
|
11
10
|
result = subject.duration(1.0)
|
12
|
-
result.
|
13
|
-
result.to_f.
|
11
|
+
expect(result).to match(/^\d+\.\d{6}$/)
|
12
|
+
expect(result.to_f).to eql(1.0)
|
14
13
|
end
|
15
|
-
it
|
14
|
+
it 'should handle integer parameter' do
|
16
15
|
result = subject.duration(1)
|
17
|
-
result.
|
18
|
-
result.to_f.
|
16
|
+
expect(result).to match(/^\d+\.\d{6}$/)
|
17
|
+
expect(result.to_f).to eql(1.0)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
21
|
describe '#header' do
|
23
|
-
it
|
24
|
-
result = capture(:stderr){ subject.header(nil) }
|
25
|
-
result.
|
22
|
+
it 'should output a blank line for nil parameters' do
|
23
|
+
result = capture(:stderr) { subject.header(nil) }
|
24
|
+
expect(result).to eql("\n")
|
26
25
|
end
|
27
|
-
it
|
28
|
-
result = capture(:stderr){ subject.header(
|
29
|
-
result.
|
26
|
+
it 'should convert an arbitrary array of strings and numbers to a space-delimited output to stderr' do
|
27
|
+
result = capture(:stderr) { subject.header('string', 1.0, 'another string', 2.0) }
|
28
|
+
expect(result).to eql("string 1.0 another string 2.0\n")
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
describe '#log' do
|
34
|
-
it
|
35
|
-
result = capture(:stdout){ subject.log(nil) }
|
36
|
-
result.
|
33
|
+
it 'should output time only for nil parameters' do
|
34
|
+
result = capture(:stdout) { subject.log(nil) }
|
35
|
+
expect(result).to match(/^.+Z,$/)
|
37
36
|
end
|
38
|
-
it
|
39
|
-
result = capture(:stdout){ subject.log(true,1.0,nil) }
|
40
|
-
result.
|
37
|
+
it 'should log successful message (boolean,float,nil) to stdout' do
|
38
|
+
result = capture(:stdout) { subject.log(true, 1.0, nil) }
|
39
|
+
expect(result).to match(/^.+Z,true,1.0,$/)
|
41
40
|
end
|
42
|
-
it
|
43
|
-
result = capture(:stdout){ subject.log(false,nil,
|
44
|
-
result.
|
41
|
+
it 'should log unsuccessful message (boolean,nil,string) to stdout' do
|
42
|
+
result = capture(:stdout) { subject.log(false, nil, 'message') }
|
43
|
+
expect(result).to match(/^.+Z,false,,message$/)
|
45
44
|
end
|
46
45
|
end
|
47
|
-
|
48
|
-
end
|
46
|
+
end
|
data/spec/shell_spec.rb
CHANGED
@@ -2,22 +2,21 @@ require 'spec_helper'
|
|
2
2
|
require 'getoptions'
|
3
3
|
|
4
4
|
describe Igp::Shell do
|
5
|
-
|
6
|
-
describe "base configuration" do
|
5
|
+
describe 'base configuration' do
|
7
6
|
context 'without destination specified' do
|
8
7
|
before do
|
9
8
|
@options = GetOptions.new(Igp::Shell::OPTIONS, [])
|
10
9
|
end
|
11
|
-
it
|
12
|
-
expect { Igp::Shell.new(@options,[]) }.to_not raise_error
|
10
|
+
it 'should initialize without error' do
|
11
|
+
expect { Igp::Shell.new(@options, []) }.to_not raise_error
|
13
12
|
end
|
14
|
-
it
|
15
|
-
Igp::Shell.respond_to
|
16
|
-
Igp::Shell.new(@options,[]).respond_to
|
13
|
+
it 'should provide help/usage' do
|
14
|
+
expect(Igp::Shell).to respond_to(:usage)
|
15
|
+
expect(Igp::Shell.new(@options, [])).to respond_to(:usage)
|
17
16
|
end
|
18
|
-
it
|
19
|
-
shell = Igp::Shell.new(@options,[])
|
20
|
-
shell.
|
17
|
+
it 'should print usage when run' do
|
18
|
+
shell = Igp::Shell.new(@options, [])
|
19
|
+
expect(shell).to receive(:usage)
|
21
20
|
shell.run
|
22
21
|
end
|
23
22
|
end
|
@@ -25,137 +24,137 @@ describe Igp::Shell do
|
|
25
24
|
before do
|
26
25
|
@options_server_value = 'example.com'
|
27
26
|
@options = GetOptions.new(Igp::Shell::OPTIONS, [])
|
28
|
-
@shell = Igp::Shell.new(@options,[@options_server_value])
|
27
|
+
@shell = Igp::Shell.new(@options, [@options_server_value])
|
29
28
|
end
|
30
|
-
it
|
31
|
-
@shell.options[:interval].
|
32
|
-
@shell.options[:limit].
|
29
|
+
it 'should default to 1 second infinte intervals' do
|
30
|
+
expect(@shell.options[:interval]).to eql(1)
|
31
|
+
expect(@shell.options[:limit]).to be_nil
|
33
32
|
end
|
34
|
-
it
|
35
|
-
@shell.options[:host].
|
36
|
-
@shell.options[:type].
|
33
|
+
it 'should accept server and default to icmp ping' do
|
34
|
+
expect(@shell.options[:host]).to eql(@options_server_value)
|
35
|
+
expect(@shell.options[:type]).to eql(:icmp)
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
40
|
-
|
41
|
-
describe
|
39
|
+
|
40
|
+
describe 'tcp configuration' do
|
42
41
|
before(:each) do
|
43
42
|
@type = :tcp
|
44
43
|
@host = 'localhost'
|
45
44
|
@port = 843
|
46
|
-
@options_server_value = "#{@type
|
45
|
+
@options_server_value = "#{@type}://#{@host}:#{@port}"
|
47
46
|
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
48
47
|
end
|
49
|
-
it
|
50
|
-
@shell.options[:url].
|
48
|
+
it 'should support url accessor' do
|
49
|
+
expect(@shell.options[:url]).to eql(@options_server_value)
|
51
50
|
end
|
52
|
-
it
|
53
|
-
@shell.options[:type].
|
51
|
+
it 'should default to tcp ping with url when given server with tcp protocol setting' do
|
52
|
+
expect(@shell.options[:type]).to eql(@type)
|
54
53
|
end
|
55
|
-
it
|
56
|
-
@shell.options[:host].
|
57
|
-
@shell.options[:port].
|
54
|
+
it 'should resolve host/port' do
|
55
|
+
expect(@shell.options[:host]).to eql(@host)
|
56
|
+
expect(@shell.options[:port]).to eql(@port)
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
|
-
describe
|
60
|
+
describe 'udp configuration' do
|
62
61
|
before(:each) do
|
63
62
|
@type = :udp
|
64
63
|
@host = 'localhost'
|
65
64
|
@port = 22
|
66
|
-
@options_server_value = "#{@type
|
65
|
+
@options_server_value = "#{@type}://#{@host}:#{@port}"
|
67
66
|
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
68
67
|
end
|
69
|
-
it
|
70
|
-
@shell.options[:url].
|
68
|
+
it 'should support url accessor' do
|
69
|
+
expect(@shell.options[:url]).to eql(@options_server_value)
|
71
70
|
end
|
72
|
-
it
|
73
|
-
@shell.options[:type].
|
71
|
+
it 'should default to tcp ping with url when given server with tcp protocol setting' do
|
72
|
+
expect(@shell.options[:type]).to eql(@type)
|
74
73
|
end
|
75
|
-
it
|
76
|
-
@shell.options[:host].
|
77
|
-
@shell.options[:port].
|
74
|
+
it 'should resolve host/port' do
|
75
|
+
expect(@shell.options[:host]).to eql(@host)
|
76
|
+
expect(@shell.options[:port]).to eql(@port)
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
|
-
describe
|
80
|
+
describe 'http configuration' do
|
82
81
|
before(:each) do
|
83
82
|
@type = :http
|
84
83
|
@host = 'localhost'
|
85
84
|
@port = 80
|
86
|
-
@options_server_value = "#{@type
|
85
|
+
@options_server_value = "#{@type}://#{@host}"
|
87
86
|
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
88
87
|
end
|
89
|
-
it
|
90
|
-
@shell.options[:url].
|
88
|
+
it 'should support url accessor' do
|
89
|
+
expect(@shell.options[:url]).to eql(@options_server_value)
|
91
90
|
end
|
92
|
-
it
|
93
|
-
@shell.options[:type].
|
91
|
+
it 'should default to tcp ping with url when given server with tcp protocol setting' do
|
92
|
+
expect(@shell.options[:type]).to eql(@type)
|
94
93
|
end
|
95
|
-
it
|
96
|
-
@shell.options[:host].
|
97
|
-
@shell.options[:port].
|
94
|
+
it 'should resolve host/port' do
|
95
|
+
expect(@shell.options[:host]).to eql(@host)
|
96
|
+
expect(@shell.options[:port]).to eql(@port)
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
|
-
describe
|
100
|
+
describe 'https configuration' do
|
102
101
|
before(:each) do
|
103
102
|
@type = :https
|
104
103
|
@host = 'localhost'
|
105
104
|
@port = 443
|
106
|
-
@options_server_value = "#{@type
|
105
|
+
@options_server_value = "#{@type}://#{@host}"
|
107
106
|
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
108
107
|
end
|
109
|
-
it
|
110
|
-
@shell.options[:url].
|
108
|
+
it 'should support url accessor' do
|
109
|
+
expect(@shell.options[:url]).to eql(@options_server_value)
|
111
110
|
end
|
112
|
-
it
|
113
|
-
@shell.options[:type].
|
111
|
+
it 'should default to tcp ping with url when given server with tcp protocol setting' do
|
112
|
+
expect(@shell.options[:type]).to eql(@type)
|
114
113
|
end
|
115
|
-
it
|
116
|
-
@shell.options[:host].
|
117
|
-
@shell.options[:port].
|
114
|
+
it 'should resolve host/port' do
|
115
|
+
expect(@shell.options[:host]).to eql(@host)
|
116
|
+
expect(@shell.options[:port]).to eql(@port)
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "ldaps configuration" do
|
142
|
-
before(:each) do
|
143
|
-
@type = :ldaps
|
144
|
-
@host = 'localhost'
|
145
|
-
@port = 636
|
146
|
-
@options_server_value = "#{@type.to_s}://#{@host}"
|
147
|
-
@shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
148
|
-
end
|
149
|
-
it "should support url accessor" do
|
150
|
-
@shell.options[:url].should eql(@options_server_value)
|
151
|
-
end
|
152
|
-
it "should default to tcp ping with url when given server with tcp protocol setting" do
|
153
|
-
@shell.options[:type].should eql(@type)
|
154
|
-
end
|
155
|
-
it "should resolve host/port" do
|
156
|
-
@shell.options[:host].should eql(@host)
|
157
|
-
@shell.options[:port].should eql(@port)
|
158
|
-
end
|
159
|
-
end
|
120
|
+
# TODO: LDAP was retired from net-ping. to add back in one way or another
|
121
|
+
# describe 'ldap configuration' do
|
122
|
+
# before(:each) do
|
123
|
+
# @type = :ldap
|
124
|
+
# @host = 'localhost'
|
125
|
+
# @port = 389
|
126
|
+
# @options_server_value = "#{@type}://#{@host}"
|
127
|
+
# @shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
128
|
+
# end
|
129
|
+
# it 'should support url accessor' do
|
130
|
+
# expect(@shell.options[:url]).to eql(@options_server_value)
|
131
|
+
# end
|
132
|
+
# it 'should default to tcp ping with url when given server with tcp protocol setting' do
|
133
|
+
# expect(@shell.options[:type]).to eql(@type)
|
134
|
+
# end
|
135
|
+
# it 'should resolve host/port' do
|
136
|
+
# expect(@shell.options[:host]).to eql(@host)
|
137
|
+
# expect(@shell.options[:port]).to eql(@port)
|
138
|
+
# end
|
139
|
+
# end
|
160
140
|
|
161
|
-
|
141
|
+
# describe 'ldaps configuration' do
|
142
|
+
# before(:each) do
|
143
|
+
# @type = :ldaps
|
144
|
+
# @host = 'localhost'
|
145
|
+
# @port = 636
|
146
|
+
# @options_server_value = "#{@type}://#{@host}"
|
147
|
+
# @shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
|
148
|
+
# end
|
149
|
+
# it 'should support url accessor' do
|
150
|
+
# expect(@shell.options[:url]).to eql(@options_server_value)
|
151
|
+
# end
|
152
|
+
# it 'should default to tcp ping with url when given server with tcp protocol setting' do
|
153
|
+
# expect(@shell.options[:type]).to eql(@type)
|
154
|
+
# end
|
155
|
+
# it 'should resolve host/port' do
|
156
|
+
# expect(@shell.options[:host]).to eql(@host)
|
157
|
+
# expect(@shell.options[:port]).to eql(@port)
|
158
|
+
# end
|
159
|
+
# end
|
160
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,13 +2,13 @@ require 'igp'
|
|
2
2
|
require 'stringio'
|
3
3
|
|
4
4
|
def capture(*streams)
|
5
|
-
streams.map!
|
5
|
+
streams.map!(&:to_s)
|
6
6
|
begin
|
7
7
|
result = StringIO.new
|
8
|
-
streams.each { |stream| eval "$#{stream} = result" }
|
8
|
+
streams.each { |stream| eval "$#{stream} = result # $#{stream} = result" }
|
9
9
|
yield
|
10
10
|
ensure
|
11
|
-
streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
|
11
|
+
streams.each { |stream| eval("$#{stream} = #{stream.upcase} # $#{stream} = #{stream.upcase}") }
|
12
12
|
end
|
13
13
|
result.string
|
14
|
-
end
|
14
|
+
end
|