net-ping 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/README +4 -6
- data/Rakefile +11 -24
- data/doc/ping.txt +1 -3
- data/lib/net/ping.rb +4 -2
- data/lib/net/ping/external.rb +106 -99
- data/lib/net/ping/http.rb +74 -71
- data/lib/net/ping/ping.rb +3 -3
- data/lib/net/ping/tcp.rb +66 -66
- data/lib/net/ping/udp.rb +94 -94
- data/net-ping.gemspec +28 -26
- data/test/test_net_ping.rb +11 -3
- data/test/test_net_ping_external.rb +63 -68
- data/test/test_net_ping_http.rb +103 -74
- data/test/test_net_ping_icmp.rb +0 -4
- data/test/test_net_ping_tcp.rb +79 -83
- data/test/test_net_ping_udp.rb +108 -88
- data/test/test_net_ping_wmi.rb +0 -4
- metadata +22 -11
@@ -9,84 +9,79 @@ gem 'test-unit'
|
|
9
9
|
|
10
10
|
require 'test/unit'
|
11
11
|
require 'net/ping/external'
|
12
|
-
include Net
|
13
12
|
|
14
|
-
class
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
class TC_Net_Ping_External < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@host = 'www.ruby-lang.org'
|
16
|
+
@bogus = 'foo.bar.baz'
|
17
|
+
@pe = Net::Ping::External.new(@host)
|
18
|
+
@bad = Net::Ping::External.new(@bogus)
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
assert_respond_to(@pe, :ping)
|
28
|
-
assert_nothing_raised{ @pe.ping }
|
29
|
-
assert_nothing_raised{ @pe.ping(@host) }
|
30
|
-
end
|
21
|
+
def test_ping
|
22
|
+
assert_respond_to(@pe, :ping)
|
23
|
+
assert_nothing_raised{ @pe.ping }
|
24
|
+
assert_nothing_raised{ @pe.ping(@host) }
|
25
|
+
end
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
27
|
+
def test_ping_aliases
|
28
|
+
assert_respond_to(@pe, :ping?)
|
29
|
+
assert_respond_to(@pe, :pingecho)
|
30
|
+
assert_nothing_raised{ @pe.ping? }
|
31
|
+
assert_nothing_raised{ @pe.ping?(@host) }
|
32
|
+
assert_nothing_raised{ @pe.pingecho }
|
33
|
+
assert_nothing_raised{ @pe.pingecho(@host) }
|
34
|
+
end
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
def test_good_ping
|
37
|
+
assert_equal(true, @pe.ping?)
|
38
|
+
end
|
44
39
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
def test_bad_ping
|
41
|
+
assert_equal(false, @bad.ping?)
|
42
|
+
assert_equal(false, @bad.exception.nil?, "Bad exception data")
|
43
|
+
end
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
def test_duration
|
46
|
+
assert_nothing_raised{ @pe.ping }
|
47
|
+
assert_respond_to(@pe, :duration)
|
48
|
+
assert_kind_of(Float, @pe.duration)
|
49
|
+
end
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
def test_host
|
52
|
+
assert_respond_to(@pe, :host)
|
53
|
+
assert_respond_to(@pe, :host=)
|
54
|
+
assert_equal('www.ruby-lang.org', @pe.host)
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
57
|
+
def test_port
|
58
|
+
assert_respond_to(@pe, :port)
|
59
|
+
assert_respond_to(@pe, :port=)
|
60
|
+
assert_equal(7, @pe.port)
|
61
|
+
end
|
67
62
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
63
|
+
def test_timeout
|
64
|
+
assert_respond_to(@pe, :timeout)
|
65
|
+
assert_respond_to(@pe, :timeout=)
|
66
|
+
assert_equal(5, @pe.timeout)
|
67
|
+
end
|
73
68
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
def test_exception
|
70
|
+
assert_respond_to(@pe, :exception)
|
71
|
+
assert_nothing_raised{ @pe.ping }
|
72
|
+
assert_nothing_raised{ @bad.ping }
|
73
|
+
assert_nil(@pe.exception)
|
74
|
+
assert_not_nil(@bad.exception)
|
75
|
+
end
|
81
76
|
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
def test_warning
|
78
|
+
assert_respond_to(@pe, :warning)
|
79
|
+
end
|
85
80
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
81
|
+
def teardown
|
82
|
+
@host = nil
|
83
|
+
@bogus = nil
|
84
|
+
@pe = nil
|
85
|
+
@bad = nil
|
86
|
+
end
|
92
87
|
end
|
data/test/test_net_ping_http.rb
CHANGED
@@ -9,78 +9,107 @@ gem 'test-unit'
|
|
9
9
|
|
10
10
|
require 'test/unit'
|
11
11
|
require 'net/ping/http'
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
12
|
+
|
13
|
+
class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@uri = 'http://www.google.com/index.html'
|
16
|
+
@http = Net::Ping::HTTP.new(@uri, 80, 30)
|
17
|
+
@bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'ping basic functionality' do
|
21
|
+
assert_respond_to(@http, :ping)
|
22
|
+
assert_nothing_raised{ @http.ping }
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'ping returns a boolean value' do
|
26
|
+
assert_boolean(@http.ping?)
|
27
|
+
assert_boolean(@bad.ping?)
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'ping? is an alias for ping' do
|
31
|
+
assert_alias_method(@http, :ping?, :ping)
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'pingecho is an alias for ping' do
|
35
|
+
assert_alias_method(@http, :pingecho, :ping)
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'ping should succeed for a valid website' do
|
39
|
+
assert_true(@http.ping?)
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'ping should fail for an invalid website' do
|
43
|
+
assert_false(@bad.ping?)
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'duration basic functionality' do
|
47
|
+
assert_respond_to(@http, :duration)
|
48
|
+
assert_nothing_raised{ @http.ping }
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'duration returns a float value on a successful ping' do
|
52
|
+
assert_true(@http.ping)
|
53
|
+
assert_kind_of(Float, @http.duration)
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'duration is nil on an unsuccessful ping' do
|
57
|
+
assert_false(@bad.ping)
|
58
|
+
assert_nil(@http.duration)
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'host attribute basic functionality' do
|
62
|
+
assert_respond_to(@http, :host)
|
63
|
+
assert_respond_to(@http, :host=)
|
64
|
+
assert_equal('http://www.google.com/index.html', @http.host)
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'uri is an alias for host' do
|
68
|
+
assert_alias_method(@http, :uri, :host)
|
69
|
+
assert_alias_method(@http, :uri=, :host=)
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'port attribute basic functionality' do
|
73
|
+
assert_respond_to(@http, :port)
|
74
|
+
assert_respond_to(@http, :port=)
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'port attribute expected value' do
|
78
|
+
assert_equal(80, @http.port)
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'timeout attribute basic functionality' do
|
82
|
+
assert_respond_to(@http, :timeout)
|
83
|
+
assert_respond_to(@http, :timeout=)
|
84
|
+
end
|
85
|
+
|
86
|
+
test 'timeout attribute expected values' do
|
87
|
+
assert_equal(30, @http.timeout)
|
88
|
+
assert_equal(5, @bad.timeout)
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'exception attribute basic functionality' do
|
92
|
+
assert_respond_to(@http, :exception)
|
93
|
+
assert_nil(@http.exception)
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'exception attribute is nil if the ping is successful' do
|
97
|
+
assert_true(@http.ping)
|
98
|
+
assert_nil(@http.exception)
|
99
|
+
end
|
100
|
+
|
101
|
+
test 'exception attribute is not nil if the ping is unsuccessful' do
|
102
|
+
assert_false(@bad.ping)
|
103
|
+
assert_not_nil(@bad.exception)
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'warning attribute basic functionality' do
|
107
|
+
assert_respond_to(@http, :warning)
|
108
|
+
assert_nil(@http.warning)
|
109
|
+
end
|
110
|
+
|
111
|
+
def teardown
|
112
|
+
@uri = nil
|
113
|
+
@http = nil
|
114
|
+
end
|
86
115
|
end
|
data/test/test_net_ping_icmp.rb
CHANGED
data/test/test_net_ping_tcp.rb
CHANGED
@@ -12,101 +12,97 @@ require 'net/ping/tcp'
|
|
12
12
|
include Net
|
13
13
|
|
14
14
|
class TC_PingTCP < Test::Unit::TestCase
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def setup
|
16
|
+
@host = 'www.ruby-lang.org'
|
17
|
+
@port = 'ftp'
|
18
|
+
@tcp = Ping::TCP.new(@host, @port)
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
assert_respond_to(@tcp, :ping)
|
27
|
-
assert_nothing_raised{ @tcp.ping }
|
28
|
-
assert_nothing_raised{ @tcp.ping(@host) }
|
29
|
-
end
|
21
|
+
def test_ping
|
22
|
+
assert_respond_to(@tcp, :ping)
|
23
|
+
assert_nothing_raised{ @tcp.ping }
|
24
|
+
assert_nothing_raised{ @tcp.ping(@host) }
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
27
|
+
def test_ping_aliases
|
28
|
+
assert_respond_to(@tcp, :ping?)
|
29
|
+
assert_respond_to(@tcp, :pingecho)
|
30
|
+
assert_nothing_raised{ @tcp.ping? }
|
31
|
+
assert_nothing_raised{ @tcp.ping?(@host) }
|
32
|
+
assert_nothing_raised{ @tcp.pingecho }
|
33
|
+
assert_nothing_raised{ @tcp.pingecho(@host) }
|
34
|
+
end
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
def test_ping_service_check_false
|
37
|
+
msg = "+this test may fail depending on your network environment+"
|
38
|
+
Ping::TCP.service_check = false
|
39
|
+
@tcp = Ping::TCP.new('localhost')
|
40
|
+
assert_false(@tcp.ping?, msg)
|
41
|
+
assert_false(@tcp.exception.nil?, "Bad exception data")
|
42
|
+
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
def test_ping_service_check_true
|
45
|
+
msg = "+this test may fail depending on your network environment+"
|
46
|
+
Ping::TCP.service_check = true
|
47
|
+
assert_true(@tcp.ping?, msg)
|
48
|
+
end
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
def test_service_check
|
51
|
+
assert_respond_to(Ping::TCP, :service_check)
|
52
|
+
assert_respond_to(Ping::TCP, :service_check=)
|
53
|
+
end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
55
|
+
# These will be removed eventually
|
56
|
+
def test_service_check_aliases
|
57
|
+
assert_respond_to(Ping::TCP, :econnrefused)
|
58
|
+
assert_respond_to(Ping::TCP, :econnrefused=)
|
59
|
+
assert_respond_to(Ping::TCP, :ecr)
|
60
|
+
assert_respond_to(Ping::TCP, :ecr=)
|
61
|
+
end
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
def test_service_check_expected_errors
|
64
|
+
assert_raises(ArgumentError){ Ping::TCP.service_check = "blah" }
|
65
|
+
end
|
70
66
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
67
|
+
# If the ping failed, the duration will be nil
|
68
|
+
def test_duration
|
69
|
+
assert_nothing_raised{ @tcp.ping }
|
70
|
+
assert_respond_to(@tcp, :duration)
|
71
|
+
omit_if(@tcp.duration.nil?, 'ping failed, skipping')
|
72
|
+
assert_kind_of(Float, @tcp.duration)
|
73
|
+
end
|
78
74
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
75
|
+
def test_host
|
76
|
+
assert_respond_to(@tcp, :host)
|
77
|
+
assert_respond_to(@tcp, :host=)
|
78
|
+
assert_equal(@host, @tcp.host)
|
79
|
+
end
|
84
80
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
81
|
+
def test_port
|
82
|
+
assert_respond_to(@tcp, :port)
|
83
|
+
assert_respond_to(@tcp, :port=)
|
84
|
+
assert_equal('ftp', @tcp.port)
|
85
|
+
end
|
90
86
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
87
|
+
def test_timeout
|
88
|
+
assert_respond_to(@tcp, :timeout)
|
89
|
+
assert_respond_to(@tcp, :timeout=)
|
90
|
+
assert_equal(5, @tcp.timeout)
|
91
|
+
end
|
96
92
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
93
|
+
def test_exception
|
94
|
+
msg = "+this test may fail depending on your network environment+"
|
95
|
+
assert_respond_to(@tcp, :exception)
|
96
|
+
assert_nothing_raised{ @tcp.ping }
|
97
|
+
assert_nil(@tcp.exception, msg)
|
98
|
+
end
|
103
99
|
|
104
|
-
|
105
|
-
|
106
|
-
|
100
|
+
def test_warning
|
101
|
+
assert_respond_to(@tcp, :warning)
|
102
|
+
end
|
107
103
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
104
|
+
def teardown
|
105
|
+
@host = nil
|
106
|
+
@tcp = nil
|
107
|
+
end
|
112
108
|
end
|