cepa-health 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  module CepaHealth
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
4
4
 
data/lib/cepa-health.rb CHANGED
@@ -11,6 +11,9 @@ module CepaHealth
11
11
  def execute(block)
12
12
  v = instance_exec(&block)
13
13
  Array === v ? record(*v) : record("Probe", v, v ? "Success" : "Failed")
14
+ rescue Exception => e
15
+ $stderr.puts "#{e.class}: #{e.message}\n#{e.backtrace * "\n"}"
16
+ record("Probe Exception", false, "#{e.class}: #{e.message}")
14
17
  end
15
18
 
16
19
  def initialize
@@ -18,9 +21,9 @@ module CepaHealth
18
21
  @success = true
19
22
  end
20
23
 
21
- def record(name, status, comment)
24
+ def record(name, status, comment = nil)
22
25
  @success = @success && !!status
23
- @records << [name.to_s, !!status, comment.to_s]
26
+ @records << [name.to_s, !!status, (comment || "").to_s]
24
27
  end
25
28
 
26
29
  def success?
@@ -13,7 +13,7 @@ describe CepaHealth::Middleware do
13
13
  end
14
14
 
15
15
  let(:rackapp) do
16
- app = ->(e) { [200, { 'Content-Type' => 'text/plain' }, ["Boom"]] }
16
+ app = ->(e) { [200, { 'Content-Type' => 'text/plain; charset=utf-8' }, ["Boom"]] }
17
17
  Rack::Lint.new CepaHealth::Middleware.new(app)
18
18
  end
19
19
 
@@ -29,22 +29,22 @@ describe CepaHealth::Middleware do
29
29
  end
30
30
 
31
31
  it "should return a 200 OK for passing probes" do
32
- CepaHealth.register("VeryUniqueTestIFear") { true }
32
+ CepaHealth.register { ["VeryUniqueTestIFear", true, ""] }
33
33
  code, headers, body = get("/healthy.html")
34
34
  code.should == 200
35
35
  body.should =~ /VeryUniqueTestIFear/
36
36
  end
37
37
 
38
38
  it "should return a 500 Error for failing probes" do
39
- CepaHealth.register("VeryUniqueTestIFear") { true }
40
- CepaHealth.register("TotallyUniqueFailure") { false }
39
+ CepaHealth.register { ["VeryUniqueTestIFear", true, ""] }
40
+ CepaHealth.register { ["TotallyUniqueFailure", false, ""] }
41
41
  code, headers, body = get("/healthy.html")
42
42
  code.should == 500
43
43
  body.should =~ /TotallyUniqueFailure/
44
44
  end
45
45
 
46
46
  it "should return a 404 if a key is set and not specified" do
47
- CepaHealth.register("VeryUniqueTestIFear") { true }
47
+ CepaHealth.register { ["VeryUniqueTestIFear", true, "" ] }
48
48
  CepaHealth.key = 'stone'
49
49
  code, headers, body = get("/healthy.html")
50
50
  code.should == 404
@@ -52,7 +52,7 @@ describe CepaHealth::Middleware do
52
52
  end
53
53
 
54
54
  it "should return successful if a key is set and specified" do
55
- CepaHealth.register("VeryUniqueTestIFear") { true }
55
+ CepaHealth.register { ['VeryUniqueTestIFear', true, "" ] }
56
56
  CepaHealth.key = 'stone'
57
57
  code, headers, body = get("/healthy.html", 'QUERY_STRING' => 'key=stone')
58
58
  code.should == 200
@@ -60,10 +60,10 @@ describe CepaHealth::Middleware do
60
60
  end
61
61
 
62
62
  it "should filter responses if they have different levels" do
63
- CepaHealth.register("error1", "error") { false }
64
- CepaHealth.register("error2", "error") { false }
65
- CepaHealth.register("warn1", "warn") { true }
66
- CepaHealth.register("warn2", "warn") { true }
63
+ CepaHealth.register("error") { ['error1', false, ""] }
64
+ CepaHealth.register("error") { ['error2', false, ""] }
65
+ CepaHealth.register("warn") { ['warn1', true, ""] }
66
+ CepaHealth.register("warn") { ['warn2', true, ""] }
67
67
  CepaHealth.key = 'stone'
68
68
 
69
69
  code, headers, body = get("/healthy.txt", 'QUERY_STRING' => 'key=stone')
@@ -96,100 +96,3 @@ describe CepaHealth::Middleware do
96
96
  end
97
97
 
98
98
  end
99
- # describe Rack::Health do
100
- # def env(url='/', *args)
101
- # Rack::MockRequest.env_for(url, *args)
102
- # end
103
-
104
- # let(:base_app) do
105
- # lambda do |env|
106
- # [200, {'Content-Type' => 'text/plain'}, ["I'm base_app"]]
107
- # end
108
- # end
109
- # let(:app) { Rack::Lint.new Rack::Health.new(base_app, rack_health_options) }
110
- # let(:rack_health_options) { {} }
111
- # let(:status) { subject[0] }
112
- # let(:body) { str = ''; subject[2].each {|s| str += s }; str }
113
-
114
- # describe 'with default options' do
115
- # let(:rack_health_options) { {} }
116
-
117
- # describe '/' do
118
- # subject { app.call env('/') }
119
-
120
- # it { status.should == 200 }
121
- # it { body.should == "I'm base_app" }
122
- # end
123
-
124
- # describe '/rack_health' do
125
- # subject { app.call env('/rack_health') }
126
-
127
- # it { status.should == 200 }
128
- # it { body.should == 'Rack::Health says "healthy"' }
129
- # end
130
- # end
131
-
132
- # describe 'with :sick_if' do
133
- # subject { app.call env('/rack_health') }
134
-
135
- # describe '== lambda { true }' do
136
- # let(:rack_health_options) { { :sick_if => lambda { true } } }
137
-
138
- # it { status.should == 503 }
139
- # it { body.should == 'Rack::Health says "sick"' }
140
- # end
141
-
142
- # describe '== lambda { false }' do
143
- # let(:rack_health_options) { { :sick_if => lambda { false } } }
144
-
145
- # it { status.should == 200 }
146
- # it { body.should == 'Rack::Health says "healthy"' }
147
- # end
148
- # end
149
-
150
- # describe 'with :status' do
151
- # let(:status_proc) { lambda {|healthy| healthy ? 202 : 404 } }
152
- # subject { app.call env('/rack_health') }
153
-
154
- # context 'healthy' do
155
- # let(:rack_health_options) { { :sick_if => lambda { false }, :status => status_proc } }
156
-
157
- # it { status.should == 202 }
158
- # it { body.should == 'Rack::Health says "healthy"' }
159
- # end
160
-
161
- # context 'sick' do
162
- # let(:rack_health_options) { { :sick_if => lambda { true }, :status => status_proc } }
163
-
164
- # it { status.should == 404 }
165
- # it { body.should == 'Rack::Health says "sick"' }
166
- # end
167
- # end
168
-
169
- # describe 'with :body' do
170
- # let(:body_proc) { lambda {|healthy| healthy ? 'fine' : 'bad' } }
171
- # subject { app.call env('/rack_health') }
172
-
173
- # context 'healthy' do
174
- # let(:rack_health_options) { { :sick_if => lambda { false }, :body => body_proc } }
175
-
176
- # it { status.should == 200 }
177
- # it { body.should == 'fine' }
178
- # end
179
-
180
- # context 'sick' do
181
- # let(:rack_health_options) { { :sick_if => lambda { true }, :body => body_proc } }
182
-
183
- # it { status.should == 503 }
184
- # it { body.should == 'bad' }
185
- # end
186
- # end
187
-
188
- # describe 'with :path' do
189
- # subject { app.call env('/how_are_you') }
190
- # let(:rack_health_options) { { :path => '/how_are_you' } }
191
-
192
- # it { status.should == 200 }
193
- # it { body.should == 'Rack::Health says "healthy"' }
194
- # end
195
- # end
@@ -14,17 +14,17 @@ describe CepaHealth do
14
14
 
15
15
  it "should register a failure on any unsuccessful probe" do
16
16
  standard_setup
17
- CepaHealth.register("Fail") { false }
18
- CepaHealth.register("Four") { true }
17
+ CepaHealth.register { ["Fail", false] }
18
+ CepaHealth.register { ["Four", true] }
19
19
  should_be(false, 6)
20
20
  end
21
21
 
22
22
  it "should allow the registration of probes in levels" do
23
- CepaHealth.register("One") { false }
24
- CepaHealth.register("Two", "error") { false }
25
- CepaHealth.register("Three", "warn") { true }
26
- CepaHealth.register("Four", "warn") { true }
27
- CepaHealth.register("Five", "warn") { true }
23
+ CepaHealth.register { ["One", false] }
24
+ CepaHealth.register('error') { ["Two", false] }
25
+ CepaHealth.register('warn') { ["Three", true] }
26
+ CepaHealth.register('warn') { ["Four", true] }
27
+ CepaHealth.register('warn') { ["Five", true] }
28
28
  should_be(false, 5)
29
29
  should_be(false, 2, "error")
30
30
  should_be(true, 3, "warn")
@@ -41,9 +41,9 @@ describe CepaHealth do
41
41
  end
42
42
 
43
43
  def standard_setup
44
- CepaHealth.register("One") { true }
45
- CepaHealth.register("Two") { true }
46
- CepaHealth.register("Three") { record("Three-B", true, "") }
44
+ CepaHealth.register { ["One", true] }
45
+ CepaHealth.register { ["Two", true] }
46
+ CepaHealth.register { record("Three-B", true, ""); ["Three", true] }
47
47
  end
48
48
 
49
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cepa-health
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-02 00:00:00.000000000 Z
12
+ date: 2013-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack