is_it_working-cbeer 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,144 @@
1
+ require 'spec_helper'
2
+ require 'webmock/rspec'
3
+
4
+ describe IsItWorking::UrlCheck do
5
+
6
+ before :all do
7
+ WebMock.disable_net_connect!
8
+ end
9
+
10
+ after :all do
11
+ WebMock.allow_net_connect!
12
+ end
13
+
14
+ after :each do
15
+ WebMock.reset!
16
+ end
17
+
18
+ let(:status){ IsItWorking::Status.new(:url) }
19
+
20
+ it "should succeed if the URL returns a 2xx response" do
21
+ stub_request(:get, "example.com/test?a=1").to_return(:status => [200, "Success"])
22
+ check = IsItWorking::UrlCheck.new(:get => "http://example.com/test?a=1")
23
+ check.call(status)
24
+ status.should be_success
25
+ status.messages.first.message.should == "GET http://example.com/test?a=1 responded with response '200 Success'"
26
+ end
27
+
28
+ it "should fail if the URL returns a 1xx response" do
29
+ stub_request(:get, "example.com/test?a=1").to_return(:status => [150, "Continue"])
30
+ check = IsItWorking::UrlCheck.new(:get => "http://example.com/test?a=1")
31
+ check.call(status)
32
+ status.should_not be_success
33
+ status.messages.first.message.should == "GET http://example.com/test?a=1 failed with response '150 Continue'"
34
+ end
35
+
36
+ it "should fail if the URL returns a 3xx response" do
37
+ stub_request(:get, "example.com/test?a=1").to_return(:status => [302, "Found"])
38
+ check = IsItWorking::UrlCheck.new(:get => "http://example.com/test?a=1")
39
+ check.call(status)
40
+ status.should_not be_success
41
+ status.messages.first.message.should == "GET http://example.com/test?a=1 failed with response '302 Found'"
42
+ end
43
+
44
+ it "should fail if the URL returns a 4xx response" do
45
+ stub_request(:get, "example.com/test?a=1").to_return(:status => [404, "Not Found"])
46
+ check = IsItWorking::UrlCheck.new(:get => "http://example.com/test?a=1")
47
+ check.call(status)
48
+ status.should_not be_success
49
+ status.messages.first.message.should == "GET http://example.com/test?a=1 failed with response '404 Not Found'"
50
+ end
51
+
52
+ it "should fail if the URL returns a 5xx response" do
53
+ stub_request(:get, "example.com/test?a=1").to_return(:status => [503, "Service Unavailable"])
54
+ check = IsItWorking::UrlCheck.new(:get => "http://example.com/test?a=1")
55
+ check.call(status)
56
+ status.should_not be_success
57
+ status.messages.first.message.should == "GET http://example.com/test?a=1 failed with response '503 Service Unavailable'"
58
+ end
59
+
60
+ it "should send basic authentication" do
61
+ stub_request(:get, "user:passwd@example.com/test?a=1").to_return(:status => [200, "Success"])
62
+ check = IsItWorking::UrlCheck.new(:get => "http://example.com/test?a=1", :username => "user", :password => "passwd")
63
+ check.call(status)
64
+ status.should be_success
65
+ status.messages.first.message.should == "GET http://example.com/test?a=1 responded with response '200 Success'"
66
+ end
67
+
68
+ it "should send headers with the request" do
69
+ stub_request(:get, "example.com/test?a=1").to_return(:status => [200, "Success"])
70
+ check = IsItWorking::UrlCheck.new(:get => "http://example.com/test?a=1", :headers => {"Accept-Encoding" => "gzip"})
71
+ check.call(status)
72
+ status.should be_success
73
+ status.messages.first.message.should == "GET http://example.com/test?a=1 responded with response '200 Success'"
74
+ WebMock.should have_requested(:get, "example.com/test?a=1").with(:headers => {"Accept-Encoding" => "gzip"})
75
+ end
76
+
77
+ it "should use SSL connection if URL is HTTPS" do
78
+ http = Net::HTTP.new('localhost')
79
+ Net::HTTP.should_receive(:new).with('localhost', 443).and_return(http)
80
+ request = Net::HTTP::Get.new("/test?a=1")
81
+ Net::HTTP::Get.should_receive(:new).with("/test?a=1", {}).and_return(request)
82
+ http.should_receive(:start).and_yield
83
+ http.should_receive(:request).with(request).and_return(Net::HTTPSuccess.new(nil, "200", "Success"))
84
+
85
+ check = IsItWorking::UrlCheck.new(:get => "https://localhost/test?a=1")
86
+ check.call(status)
87
+ status.should be_success
88
+ status.messages.first.message.should == "GET https://localhost/test?a=1 responded with response '200 Success'"
89
+ http.use_ssl?.should == true
90
+ http.verify_mode.should == OpenSSL::SSL::VERIFY_PEER
91
+ end
92
+
93
+ it "should be able to alias the URL in the output" do
94
+ stub_request(:get, "example.com/test").to_return(:status => [200, "Success"])
95
+ check = IsItWorking::UrlCheck.new(:get => "http://example.com/test", :alias => "service ping URL")
96
+ check.call(status)
97
+ status.should be_success
98
+ status.messages.first.message.should == "GET service ping URL responded with response '200 Success'"
99
+ end
100
+
101
+ it "should try to get the URL through a proxy" do
102
+ http = Net::HTTP.new('localhost')
103
+ Net::HTTP.should_receive(:Proxy).with('localhost', 8080, "user", "passwd").and_return(Net::HTTP)
104
+ Net::HTTP.should_receive(:new).with('localhost', 80).and_return(http)
105
+ request = Net::HTTP::Get.new("/test?a=1")
106
+ Net::HTTP::Get.should_receive(:new).with("/test?a=1", {}).and_return(request)
107
+ http.should_receive(:start).and_yield
108
+ http.should_receive(:request).with(request).and_return(Net::HTTPSuccess.new(nil, "200", "Success"))
109
+
110
+ check = IsItWorking::UrlCheck.new(:get => "http://localhost/test?a=1", :proxy => {:host => "localhost", :port => 8080, :username => "user", :password => "passwd"})
111
+ check.call(status)
112
+ status.should be_success
113
+ status.messages.first.message.should == "GET http://localhost/test?a=1 responded with response '200 Success'"
114
+ end
115
+
116
+ it "should set open and read timeouts" do
117
+ http = Net::HTTP.new('localhost')
118
+ Net::HTTP.should_receive(:new).with('localhost', 80).and_return(http)
119
+ request = Net::HTTP::Get.new("/test?a=1")
120
+ Net::HTTP::Get.should_receive(:new).with("/test?a=1", {}).and_return(request)
121
+ http.should_receive(:start).and_yield
122
+ http.should_receive(:request).with(request).and_return(Net::HTTPSuccess.new(nil, "200", "Success"))
123
+
124
+ check = IsItWorking::UrlCheck.new(:get => "http://localhost/test?a=1", :open_timeout => 1, :read_timeout => 2)
125
+ check.call(status)
126
+ status.should be_success
127
+ status.messages.first.message.should == "GET http://localhost/test?a=1 responded with response '200 Success'"
128
+ http.open_timeout.should == 1
129
+ http.read_timeout.should == 2
130
+ end
131
+
132
+ it "should fail on a timeout" do
133
+ http = Net::HTTP.new('localhost')
134
+ Net::HTTP.should_receive(:new).with('localhost', 80).and_return(http)
135
+ request = Net::HTTP::Get.new("/test?a=1")
136
+ Net::HTTP::Get.should_receive(:new).with("/test?a=1", {}).and_return(request)
137
+ http.should_receive(:start).and_raise(TimeoutError)
138
+
139
+ check = IsItWorking::UrlCheck.new(:get => "http://localhost/test?a=1", :open_timeout => 1, :read_timeout => 2)
140
+ check.call(status)
141
+ status.should_not be_success
142
+ status.messages.first.message.should match(/GET http:\/\/localhost\/test\?a=1 timed out after .* seconds/)
143
+ end
144
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_it_working-cbeer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.11
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Durand
9
+ - Chris Beer
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-06-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '2.0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: webmock
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 1.6.0
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.6.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: memcache-client
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: dalli
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rails
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: Rack handler for monitoring several parts of a web application so one
96
+ request can determine which system or dependencies are down.
97
+ email:
98
+ - mdobrota@tribune.com
99
+ - ddpr@tribune.com
100
+ - chris@cbeer.info
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files:
104
+ - README.rdoc
105
+ files:
106
+ - .gitignore
107
+ - Gemfile
108
+ - License.txt
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION
112
+ - is_it_working.gemspec
113
+ - lib/is_it_working.rb
114
+ - lib/is_it_working/checks/action_mailer_check.rb
115
+ - lib/is_it_working/checks/active_record_check.rb
116
+ - lib/is_it_working/checks/dalli_check.rb
117
+ - lib/is_it_working/checks/directory_check.rb
118
+ - lib/is_it_working/checks/memcache_check.rb
119
+ - lib/is_it_working/checks/ping_check.rb
120
+ - lib/is_it_working/checks/url_check.rb
121
+ - lib/is_it_working/filter.rb
122
+ - lib/is_it_working/handler.rb
123
+ - lib/is_it_working/status.rb
124
+ - spec/action_mailer_check_spec.rb
125
+ - spec/active_record_check_spec.rb
126
+ - spec/dalli_check_spec.rb
127
+ - spec/directory_check_spec.rb
128
+ - spec/filter_spec.rb
129
+ - spec/handler_spec.rb
130
+ - spec/memecache_check_spec.rb
131
+ - spec/ping_check_spec.rb
132
+ - spec/spec_helper.rb
133
+ - spec/status_spec.rb
134
+ - spec/url_check_spec.rb
135
+ homepage:
136
+ licenses: []
137
+ post_install_message:
138
+ rdoc_options:
139
+ - --line-numbers
140
+ - --inline-source
141
+ - --main
142
+ - README.rdoc
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ segments:
152
+ - 0
153
+ hash: -2548203515793015154
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ segments:
161
+ - 0
162
+ hash: -2548203515793015154
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 1.8.24
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Rack handler for monitoring several parts of a web application.
169
+ test_files:
170
+ - spec/action_mailer_check_spec.rb
171
+ - spec/active_record_check_spec.rb
172
+ - spec/dalli_check_spec.rb
173
+ - spec/directory_check_spec.rb
174
+ - spec/filter_spec.rb
175
+ - spec/handler_spec.rb
176
+ - spec/memecache_check_spec.rb
177
+ - spec/ping_check_spec.rb
178
+ - spec/spec_helper.rb
179
+ - spec/status_spec.rb
180
+ - spec/url_check_spec.rb