igp 0.0.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
- describe "base initialization without options" do
7
- it "should not set ping_handler" do
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 "should not set limit" do
11
- subject.limit.should be_nil
9
+ it 'should not set limit' do
10
+ expect(subject.limit).to be_nil
12
11
  end
13
- it "should default interval to 5 sec" do
14
- subject.interval.should eql(5)
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 "ping_handler configuration" do
19
- it "should be Net::Ping::External for :icmp" do
20
- options = { :type => :icmp, :host => 'localhost', :port => nil}
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.should be_a(Net::Ping::TCP)
21
+ expect(base.ping_handler).to be_a(Net::Ping::External)
33
22
  end
34
- it "should be Net::Ping::HTTP for :http" do
35
- options = { :type => :http, :url => 'http://localhost'}
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.should be_a(Net::Ping::HTTP)
26
+ expect(base.ping_handler).to be_a(Net::Ping::UDP)
38
27
  end
39
- it "should be Net::Ping::HTTP for :https" do
40
- options = { :type => :https, :url => 'https://localhost'}
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.should be_a(Net::Ping::HTTP)
31
+ expect(base.ping_handler).to be_a(Net::Ping::TCP)
43
32
  end
44
- it "should be Net::Ping::LDAP for :ldap" do
45
- options = { :type => :ldap, :url => 'ldap://localhost'}
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.should be_a(Net::Ping::LDAP)
36
+ expect(base.ping_handler).to be_a(Net::Ping::HTTP)
48
37
  end
49
- it "should be Net::Ping::LDAP for :ldaps" do
50
- options = { :type => :ldaps, :url => 'ldaps://localhost'}
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.should be_a(Net::Ping::LDAP)
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 "#run" do
56
+ describe '#run' do
57
57
  before do
58
- @good = Igp::Base.new({ :type => :icmp, :host => 'localhost', :port => nil, :limit => 1})
58
+ @good = Igp::Base.new({ type: :icmp, host: 'localhost', port: nil, limit: 1 })
59
59
  end
60
- it "should print header and log a ping result" do
61
- @good.formatter.should_receive(:header)
62
- @good.formatter.should_receive(:log)
63
- capture(:stdout,:stderr){ @good.run }
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 "should return nil for nil duration" do
8
- subject.duration(nil).should be_nil
6
+ it 'should return nil for nil duration' do
7
+ expect(subject.duration(nil)).to be_nil
9
8
  end
10
- it "should return string to 6 decimal places for non-nil duration" do
9
+ it 'should return string to 6 decimal places for non-nil duration' do
11
10
  result = subject.duration(1.0)
12
- result.should match(/^\d+\.\d{6}$/)
13
- result.to_f.should eql(1.0)
11
+ expect(result).to match(/^\d+\.\d{6}$/)
12
+ expect(result.to_f).to eql(1.0)
14
13
  end
15
- it "should handle integer parameter" do
14
+ it 'should handle integer parameter' do
16
15
  result = subject.duration(1)
17
- result.should match(/^\d+\.\d{6}$/)
18
- result.to_f.should eql(1.0)
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 "should output a blank line for nil parameters" do
24
- result = capture(:stderr){ subject.header(nil) }
25
- result.should eql("\n")
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 "should convert an arbitrary array of strings and numbers to a space-delimited output to stderr" do
28
- result = capture(:stderr){ subject.header("string",1.0,"another string",2.0) }
29
- result.should eql("string 1.0 another string 2.0\n")
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 "should output time only for nil parameters" do
35
- result = capture(:stdout){ subject.log(nil) }
36
- result.should match(/^.+Z,$/)
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 "should log successful message (boolean,float,nil) to stdout" do
39
- result = capture(:stdout){ subject.log(true,1.0,nil) }
40
- result.should match(/^.+Z,true,1.0,$/)
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 "should log unsuccessful message (boolean,nil,string) to stdout" do
43
- result = capture(:stdout){ subject.log(false,nil,"message") }
44
- result.should match(/^.+Z,false,,message$/)
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 "should initialize without error" do
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 "should provide help/usage" do
15
- Igp::Shell.respond_to?(:usage).should be_true
16
- Igp::Shell.new(@options,[]).respond_to?(:usage).should be_true
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 "should print usage when run" do
19
- shell = Igp::Shell.new(@options,[])
20
- shell.should_receive(:usage)
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 "should default to 1 second infinte intervals" do
31
- @shell.options[:interval].should eql(1)
32
- @shell.options[:limit].should be_nil
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 "should accept server and default to icmp ping" do
35
- @shell.options[:host].should eql(@options_server_value)
36
- @shell.options[:type].should eql(:icmp)
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 "tcp configuration" do
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.to_s}://#{@host}:#{@port}"
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 "should support url accessor" do
50
- @shell.options[:url].should eql(@options_server_value)
48
+ it 'should support url accessor' do
49
+ expect(@shell.options[:url]).to eql(@options_server_value)
51
50
  end
52
- it "should default to tcp ping with url when given server with tcp protocol setting" do
53
- @shell.options[:type].should eql(@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 "should resolve host/port" do
56
- @shell.options[:host].should eql(@host)
57
- @shell.options[:port].should eql(@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 "udp configuration" do
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.to_s}://#{@host}:#{@port}"
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 "should support url accessor" do
70
- @shell.options[:url].should eql(@options_server_value)
68
+ it 'should support url accessor' do
69
+ expect(@shell.options[:url]).to eql(@options_server_value)
71
70
  end
72
- it "should default to tcp ping with url when given server with tcp protocol setting" do
73
- @shell.options[:type].should eql(@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 "should resolve host/port" do
76
- @shell.options[:host].should eql(@host)
77
- @shell.options[:port].should eql(@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 "http configuration" do
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.to_s}://#{@host}"
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 "should support url accessor" do
90
- @shell.options[:url].should eql(@options_server_value)
88
+ it 'should support url accessor' do
89
+ expect(@shell.options[:url]).to eql(@options_server_value)
91
90
  end
92
- it "should default to tcp ping with url when given server with tcp protocol setting" do
93
- @shell.options[:type].should eql(@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 "should resolve host/port" do
96
- @shell.options[:host].should eql(@host)
97
- @shell.options[:port].should eql(@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 "https configuration" do
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.to_s}://#{@host}"
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 "should support url accessor" do
110
- @shell.options[:url].should eql(@options_server_value)
108
+ it 'should support url accessor' do
109
+ expect(@shell.options[:url]).to eql(@options_server_value)
111
110
  end
112
- it "should default to tcp ping with url when given server with tcp protocol setting" do
113
- @shell.options[:type].should eql(@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 "should resolve host/port" do
116
- @shell.options[:host].should eql(@host)
117
- @shell.options[:port].should eql(@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
- describe "ldap configuration" do
122
- before(:each) do
123
- @type = :ldap
124
- @host = 'localhost'
125
- @port = 389
126
- @options_server_value = "#{@type.to_s}://#{@host}"
127
- @shell = Igp::Shell.new(GetOptions.new(Igp::Shell::OPTIONS, []), [@options_server_value])
128
- end
129
- it "should support url accessor" do
130
- @shell.options[:url].should eql(@options_server_value)
131
- end
132
- it "should default to tcp ping with url when given server with tcp protocol setting" do
133
- @shell.options[:type].should eql(@type)
134
- end
135
- it "should resolve host/port" do
136
- @shell.options[:host].should eql(@host)
137
- @shell.options[:port].should eql(@port)
138
- end
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
- end
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! { |stream| stream.to_s }
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