net-ping 1.7.2-universal-mingw32 → 1.7.3-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,230 +1,230 @@
1
- #################################################################################
2
- # test_net_ping_http.rb
3
- #
4
- # Test case for the Net::PingHTTP class. This should be run via the 'test' or
5
- # 'test:http' Rake task.
6
- #################################################################################
7
- require 'test-unit'
8
- require 'fakeweb'
9
- require 'net/ping/http'
10
-
11
- class TC_Net_Ping_HTTP < Test::Unit::TestCase
12
- def setup
13
- ENV['http_proxy'] = ENV['https_proxy'] = ENV['no_proxy'] = nil
14
- @uri = 'http://www.google.com/index.html'
15
- @uri_https = 'https://encrypted.google.com'
16
- @proxy = 'http://username:password@proxymoxie:3128'
17
- FakeWeb.allow_net_connect = false
18
-
19
- FakeWeb.register_uri(:get, @uri, :body => "PONG")
20
- FakeWeb.register_uri(:head, @uri, :body => "PONG")
21
- FakeWeb.register_uri(:head, @uri_https, :body => "PONG")
22
- FakeWeb.register_uri(:get, @uri_https, :body => "PONG")
23
- FakeWeb.register_uri(:head, "http://jigsaw.w3.org/HTTP/300/302.html",
24
- :body => "PONG",
25
- :location => "#{@uri}",
26
- :status => ["302", "Found"])
27
-
28
- FakeWeb.register_uri(:any, 'http://www.blabfoobarurghxxxx.com', :exception => SocketError)
29
- FakeWeb.register_uri(:head, 'http://http502.com',
30
- :body => "",
31
- :status => ["502", "Bad Gateway"])
32
-
33
- @http = Net::Ping::HTTP.new(@uri, 80, 30)
34
- @bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
35
- end
36
-
37
- test 'ping basic functionality' do
38
- assert_respond_to(@http, :ping)
39
- assert_nothing_raised{ @http.ping }
40
- end
41
-
42
- test 'ping returns a boolean value' do
43
- assert_boolean(@http.ping?)
44
- assert_boolean(@bad.ping?)
45
- end
46
-
47
- test 'ping? is an alias for ping' do
48
- assert_alias_method(@http, :ping?, :ping)
49
- end
50
-
51
- test 'pingecho is an alias for ping' do
52
- assert_alias_method(@http, :pingecho, :ping)
53
- end
54
-
55
- test 'ping should succeed for a valid website' do
56
- assert_true(@http.ping?)
57
- end
58
-
59
- test 'ping should fail for an invalid website' do
60
- assert_false(@bad.ping?)
61
- end
62
-
63
- test 'duration basic functionality' do
64
- assert_respond_to(@http, :duration)
65
- assert_nothing_raised{ @http.ping }
66
- end
67
-
68
- test 'duration returns a float value on a successful ping' do
69
- assert_true(@http.ping)
70
- assert_kind_of(Float, @http.duration)
71
- end
72
-
73
- test 'duration is nil on an unsuccessful ping' do
74
- assert_false(@bad.ping)
75
- assert_nil(@http.duration)
76
- end
77
-
78
- test 'host attribute basic functionality' do
79
- assert_respond_to(@http, :host)
80
- assert_respond_to(@http, :host=)
81
- assert_equal('http://www.google.com/index.html', @http.host)
82
- end
83
-
84
- test 'uri is an alias for host' do
85
- assert_alias_method(@http, :uri, :host)
86
- assert_alias_method(@http, :uri=, :host=)
87
- end
88
-
89
- test 'port attribute basic functionality' do
90
- assert_respond_to(@http, :port)
91
- assert_respond_to(@http, :port=)
92
- end
93
-
94
- test 'port attribute expected value' do
95
- assert_equal(80, @http.port)
96
- end
97
-
98
- test 'timeout attribute basic functionality' do
99
- assert_respond_to(@http, :timeout)
100
- assert_respond_to(@http, :timeout=)
101
- end
102
-
103
- test 'timeout attribute expected values' do
104
- assert_equal(30, @http.timeout)
105
- assert_equal(5, @bad.timeout)
106
- end
107
-
108
- test 'exception attribute basic functionality' do
109
- assert_respond_to(@http, :exception)
110
- assert_nil(@http.exception)
111
- end
112
-
113
- test 'exception attribute is nil if the ping is successful' do
114
- assert_true(@http.ping)
115
- assert_nil(@http.exception)
116
- end
117
-
118
- test 'exception attribute is not nil if the ping is unsuccessful' do
119
- assert_false(@bad.ping)
120
- assert_not_nil(@bad.exception)
121
- end
122
-
123
- test 'warning attribute basic functionality' do
124
- assert_respond_to(@http, :warning)
125
- assert_nil(@http.warning)
126
- end
127
-
128
- test 'code attribute is set' do
129
- assert_true(@http.ping)
130
- assert_equal('200', @http.code)
131
- end
132
-
133
- test 'user_agent accessor is defined' do
134
- assert_respond_to(@http, :user_agent)
135
- assert_respond_to(@http, :user_agent=)
136
- end
137
-
138
- test 'user_agent defaults to nil' do
139
- assert_nil(@http.user_agent)
140
- end
141
-
142
- test 'ping with user agent' do
143
- @http.user_agent = "KDDI-CA32"
144
- assert_true(@http.ping)
145
- end
146
-
147
- test 'redirect_limit accessor is defined' do
148
- assert_respond_to(@http, :redirect_limit)
149
- assert_respond_to(@http, :redirect_limit=)
150
- end
151
-
152
- test 'redirect_limit defaults to 5' do
153
- assert_equal(5, @http.redirect_limit)
154
- end
155
-
156
- test 'redirects succeed by default' do
157
- @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
158
- assert_true(@http.ping)
159
- end
160
-
161
- test 'redirect fail if follow_redirect is set to false' do
162
- @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
163
- @http.follow_redirect = false
164
- assert_false(@http.ping)
165
- end
166
-
167
- test 'ping with redirect limit set to zero fails' do
168
- @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
169
- @http.redirect_limit = 0
170
- assert_false(@http.ping)
171
- assert_equal("Redirect limit exceeded", @http.exception)
172
- end
173
-
174
- test 'http 502 sets exception' do
175
- @http = Net::Ping::HTTP.new("http://http502.com")
176
- assert_false(@http.ping)
177
- assert_equal('Bad Gateway', @http.exception)
178
- end
179
-
180
- test 'http 502 sets code' do
181
- @http = Net::Ping::HTTP.new("http://http502.com")
182
- assert_false(@http.ping)
183
- assert_equal('502', @http.code)
184
- end
185
-
186
- test 'ping against https site defaults to port 443' do
187
- @http = Net::Ping::HTTP.new(@uri_https)
188
- assert_equal(443, @http.port)
189
- end
190
-
191
- test 'ping against https site works as expected' do
192
- @http = Net::Ping::HTTP.new(@uri_https)
193
- assert_true(@http.ping)
194
- end
195
-
196
- test 'ping with get option' do
197
- @http = Net::Ping::HTTP.new(@uri)
198
- @http.get_request = true
199
- assert_true(@http.ping)
200
- end
201
-
202
- test 'ping with http proxy' do
203
- ENV['http_proxy'] = "http://proxymoxie:3128"
204
- @http = Net::Ping::HTTP.new(@uri)
205
- @http.get_request = true
206
- assert_true(@http.ping)
207
- assert_true(@http.proxied)
208
- end
209
-
210
- test 'ping with https proxy' do
211
- ENV['https_proxy'] = "http://proxymoxie:3128"
212
- @http = Net::Ping::HTTP.new(@uri_https)
213
- @http.get_request = true
214
- assert_true(@http.ping)
215
- assert_true(@http.proxied)
216
- end
217
-
218
- test 'ping with no_proxy' do
219
- ENV['no_proxy'] = "google.com"
220
- @http = Net::Ping::HTTP.new(@uri)
221
- @http.get_request = true
222
- assert_true(@http.ping)
223
- assert_false(@http.proxied)
224
- end
225
-
226
- def teardown
227
- @uri = nil
228
- @http = nil
229
- end
230
- end
1
+ #################################################################################
2
+ # test_net_ping_http.rb
3
+ #
4
+ # Test case for the Net::PingHTTP class. This should be run via the 'test' or
5
+ # 'test:http' Rake task.
6
+ #################################################################################
7
+ require 'test-unit'
8
+ require 'fakeweb'
9
+ require 'net/ping/http'
10
+
11
+ class TC_Net_Ping_HTTP < Test::Unit::TestCase
12
+ def setup
13
+ ENV['http_proxy'] = ENV['https_proxy'] = ENV['no_proxy'] = nil
14
+ @uri = 'http://www.google.com/index.html'
15
+ @uri_https = 'https://encrypted.google.com'
16
+ @proxy = 'http://username:password@proxymoxie:3128'
17
+ FakeWeb.allow_net_connect = false
18
+
19
+ FakeWeb.register_uri(:get, @uri, :body => "PONG")
20
+ FakeWeb.register_uri(:head, @uri, :body => "PONG")
21
+ FakeWeb.register_uri(:head, @uri_https, :body => "PONG")
22
+ FakeWeb.register_uri(:get, @uri_https, :body => "PONG")
23
+ FakeWeb.register_uri(:head, "http://jigsaw.w3.org/HTTP/300/302.html",
24
+ :body => "PONG",
25
+ :location => "#{@uri}",
26
+ :status => ["302", "Found"])
27
+
28
+ FakeWeb.register_uri(:any, 'http://www.blabfoobarurghxxxx.com', :exception => SocketError)
29
+ FakeWeb.register_uri(:head, 'http://http502.com',
30
+ :body => "",
31
+ :status => ["502", "Bad Gateway"])
32
+
33
+ @http = Net::Ping::HTTP.new(@uri, 80, 30)
34
+ @bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
35
+ end
36
+
37
+ test 'ping basic functionality' do
38
+ assert_respond_to(@http, :ping)
39
+ assert_nothing_raised{ @http.ping }
40
+ end
41
+
42
+ test 'ping returns a boolean value' do
43
+ assert_boolean(@http.ping?)
44
+ assert_boolean(@bad.ping?)
45
+ end
46
+
47
+ test 'ping? is an alias for ping' do
48
+ assert_alias_method(@http, :ping?, :ping)
49
+ end
50
+
51
+ test 'pingecho is an alias for ping' do
52
+ assert_alias_method(@http, :pingecho, :ping)
53
+ end
54
+
55
+ test 'ping should succeed for a valid website' do
56
+ assert_true(@http.ping?)
57
+ end
58
+
59
+ test 'ping should fail for an invalid website' do
60
+ assert_false(@bad.ping?)
61
+ end
62
+
63
+ test 'duration basic functionality' do
64
+ assert_respond_to(@http, :duration)
65
+ assert_nothing_raised{ @http.ping }
66
+ end
67
+
68
+ test 'duration returns a float value on a successful ping' do
69
+ assert_true(@http.ping)
70
+ assert_kind_of(Float, @http.duration)
71
+ end
72
+
73
+ test 'duration is nil on an unsuccessful ping' do
74
+ assert_false(@bad.ping)
75
+ assert_nil(@http.duration)
76
+ end
77
+
78
+ test 'host attribute basic functionality' do
79
+ assert_respond_to(@http, :host)
80
+ assert_respond_to(@http, :host=)
81
+ assert_equal('http://www.google.com/index.html', @http.host)
82
+ end
83
+
84
+ test 'uri is an alias for host' do
85
+ assert_alias_method(@http, :uri, :host)
86
+ assert_alias_method(@http, :uri=, :host=)
87
+ end
88
+
89
+ test 'port attribute basic functionality' do
90
+ assert_respond_to(@http, :port)
91
+ assert_respond_to(@http, :port=)
92
+ end
93
+
94
+ test 'port attribute expected value' do
95
+ assert_equal(80, @http.port)
96
+ end
97
+
98
+ test 'timeout attribute basic functionality' do
99
+ assert_respond_to(@http, :timeout)
100
+ assert_respond_to(@http, :timeout=)
101
+ end
102
+
103
+ test 'timeout attribute expected values' do
104
+ assert_equal(30, @http.timeout)
105
+ assert_equal(5, @bad.timeout)
106
+ end
107
+
108
+ test 'exception attribute basic functionality' do
109
+ assert_respond_to(@http, :exception)
110
+ assert_nil(@http.exception)
111
+ end
112
+
113
+ test 'exception attribute is nil if the ping is successful' do
114
+ assert_true(@http.ping)
115
+ assert_nil(@http.exception)
116
+ end
117
+
118
+ test 'exception attribute is not nil if the ping is unsuccessful' do
119
+ assert_false(@bad.ping)
120
+ assert_not_nil(@bad.exception)
121
+ end
122
+
123
+ test 'warning attribute basic functionality' do
124
+ assert_respond_to(@http, :warning)
125
+ assert_nil(@http.warning)
126
+ end
127
+
128
+ test 'code attribute is set' do
129
+ assert_true(@http.ping)
130
+ assert_equal('200', @http.code)
131
+ end
132
+
133
+ test 'user_agent accessor is defined' do
134
+ assert_respond_to(@http, :user_agent)
135
+ assert_respond_to(@http, :user_agent=)
136
+ end
137
+
138
+ test 'user_agent defaults to nil' do
139
+ assert_nil(@http.user_agent)
140
+ end
141
+
142
+ test 'ping with user agent' do
143
+ @http.user_agent = "KDDI-CA32"
144
+ assert_true(@http.ping)
145
+ end
146
+
147
+ test 'redirect_limit accessor is defined' do
148
+ assert_respond_to(@http, :redirect_limit)
149
+ assert_respond_to(@http, :redirect_limit=)
150
+ end
151
+
152
+ test 'redirect_limit defaults to 5' do
153
+ assert_equal(5, @http.redirect_limit)
154
+ end
155
+
156
+ test 'redirects succeed by default' do
157
+ @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
158
+ assert_true(@http.ping)
159
+ end
160
+
161
+ test 'redirect fail if follow_redirect is set to false' do
162
+ @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
163
+ @http.follow_redirect = false
164
+ assert_false(@http.ping)
165
+ end
166
+
167
+ test 'ping with redirect limit set to zero fails' do
168
+ @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
169
+ @http.redirect_limit = 0
170
+ assert_false(@http.ping)
171
+ assert_equal("Redirect limit exceeded", @http.exception)
172
+ end
173
+
174
+ test 'http 502 sets exception' do
175
+ @http = Net::Ping::HTTP.new("http://http502.com")
176
+ assert_false(@http.ping)
177
+ assert_equal('Bad Gateway', @http.exception)
178
+ end
179
+
180
+ test 'http 502 sets code' do
181
+ @http = Net::Ping::HTTP.new("http://http502.com")
182
+ assert_false(@http.ping)
183
+ assert_equal('502', @http.code)
184
+ end
185
+
186
+ test 'ping against https site defaults to port 443' do
187
+ @http = Net::Ping::HTTP.new(@uri_https)
188
+ assert_equal(443, @http.port)
189
+ end
190
+
191
+ test 'ping against https site works as expected' do
192
+ @http = Net::Ping::HTTP.new(@uri_https)
193
+ assert_true(@http.ping)
194
+ end
195
+
196
+ test 'ping with get option' do
197
+ @http = Net::Ping::HTTP.new(@uri)
198
+ @http.get_request = true
199
+ assert_true(@http.ping)
200
+ end
201
+
202
+ test 'ping with http proxy' do
203
+ ENV['http_proxy'] = "http://proxymoxie:3128"
204
+ @http = Net::Ping::HTTP.new(@uri)
205
+ @http.get_request = true
206
+ assert_true(@http.ping)
207
+ assert_true(@http.proxied)
208
+ end
209
+
210
+ test 'ping with https proxy' do
211
+ ENV['https_proxy'] = "http://proxymoxie:3128"
212
+ @http = Net::Ping::HTTP.new(@uri_https)
213
+ @http.get_request = true
214
+ assert_true(@http.ping)
215
+ assert_true(@http.proxied)
216
+ end
217
+
218
+ test 'ping with no_proxy' do
219
+ ENV['no_proxy'] = "google.com"
220
+ @http = Net::Ping::HTTP.new(@uri)
221
+ @http.get_request = true
222
+ assert_true(@http.ping)
223
+ assert_false(@http.proxied)
224
+ end
225
+
226
+ def teardown
227
+ @uri = nil
228
+ @http = nil
229
+ end
230
+ end