fettle 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/app/controllers/fettle/health_controller.rb +6 -1
- data/config/routes.rb +1 -0
- data/lib/fettle.rb +8 -1
- data/lib/fettle/check_result.rb +19 -0
- data/lib/fettle/checker.rb +42 -0
- data/lib/fettle/checks/active_record_check.rb +32 -0
- data/lib/fettle/configuration.rb +27 -0
- data/lib/fettle/liveness_check_result.rb +15 -0
- data/lib/fettle/version.rb +1 -1
- data/spec/controllers/fettle/health_controller_spec.rb +40 -0
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/initializers/fettle.rb +5 -0
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/log/development.log +958 -0
- data/spec/dummy/log/test.log +1192 -0
- data/spec/examples.txt +24 -3
- data/spec/lib/fettle/check_result_spec.rb +38 -0
- data/spec/lib/fettle/checker_spec.rb +91 -0
- data/spec/lib/fettle/checks/active_record_check_spec.rb +35 -0
- data/spec/lib/fettle/configuration_spec.rb +27 -0
- data/spec/lib/fettle/liveness_check_result_spec.rb +38 -0
- data/spec/rails_helper.rb +2 -0
- metadata +19 -2
data/spec/examples.txt
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/controllers/fettle/health_controller_spec.rb[1:1:1:1]
|
1
|
+
example_id | status | run_time |
|
2
|
+
-------------------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/controllers/fettle/health_controller_spec.rb[1:1:1:1] | passed | 0.01177 seconds |
|
4
|
+
./spec/controllers/fettle/health_controller_spec.rb[1:1:1:2:1] | passed | 0.00176 seconds |
|
5
|
+
./spec/controllers/fettle/health_controller_spec.rb[1:1:2:1] | passed | 0.00158 seconds |
|
6
|
+
./spec/controllers/fettle/health_controller_spec.rb[1:1:2:2:1] | passed | 0.00166 seconds |
|
7
|
+
./spec/lib/fettle/check_result_spec.rb[1:1:1:1] | passed | 0.00044 seconds |
|
8
|
+
./spec/lib/fettle/check_result_spec.rb[1:1:2:1] | passed | 0.00044 seconds |
|
9
|
+
./spec/lib/fettle/check_result_spec.rb[1:2:1:1] | passed | 0.00044 seconds |
|
10
|
+
./spec/lib/fettle/check_result_spec.rb[1:2:2:1] | passed | 0.00086 seconds |
|
11
|
+
./spec/lib/fettle/checker_spec.rb[1:1:1:1] | passed | 0.00063 seconds |
|
12
|
+
./spec/lib/fettle/checker_spec.rb[1:1:1:2:1] | passed | 0.00063 seconds |
|
13
|
+
./spec/lib/fettle/checker_spec.rb[1:1:2:1] | passed | 0.00063 seconds |
|
14
|
+
./spec/lib/fettle/checker_spec.rb[1:1:2:2:1] | passed | 0.00069 seconds |
|
15
|
+
./spec/lib/fettle/checker_spec.rb[1:1:3:1] | passed | 0.00131 seconds |
|
16
|
+
./spec/lib/fettle/checker_spec.rb[1:1:3:2:1] | passed | 0.00068 seconds |
|
17
|
+
./spec/lib/fettle/checks/active_record_check_spec.rb[1:1:1:1] | passed | 0.00922 seconds |
|
18
|
+
./spec/lib/fettle/checks/active_record_check_spec.rb[1:1:2:1] | passed | 0.00154 seconds |
|
19
|
+
./spec/lib/fettle/configuration_spec.rb[1:1:1] | passed | 0.00228 seconds |
|
20
|
+
./spec/lib/fettle/configuration_spec.rb[1:2:1:1:1] | passed | 0.00142 seconds |
|
21
|
+
./spec/lib/fettle/liveness_check_result_spec.rb[1:1:1:1] | passed | 0.0005 seconds |
|
22
|
+
./spec/lib/fettle/liveness_check_result_spec.rb[1:1:2:1] | passed | 0.00049 seconds |
|
23
|
+
./spec/lib/fettle/liveness_check_result_spec.rb[1:2:1:1] | passed | 0.00045 seconds |
|
24
|
+
./spec/lib/fettle/liveness_check_result_spec.rb[1:2:2:1] | passed | 0.00041 seconds |
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fettle/check_result'
|
3
|
+
|
4
|
+
module Fettle
|
5
|
+
RSpec.describe CheckResult do
|
6
|
+
describe '#healthy?' do
|
7
|
+
subject { described_class.new(status) }
|
8
|
+
|
9
|
+
let(:status) { true }
|
10
|
+
|
11
|
+
context 'for successful checks' do
|
12
|
+
it { is_expected.to be_healthy }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'for failed checks' do
|
16
|
+
let(:status) { false }
|
17
|
+
|
18
|
+
it { is_expected.to_not be_healthy }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#status_code' do
|
23
|
+
subject { described_class.new(status).status_code }
|
24
|
+
|
25
|
+
let(:status) { true }
|
26
|
+
|
27
|
+
context 'for successful checks' do
|
28
|
+
it { is_expected.to eq(:ok) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'for failed checks' do
|
32
|
+
let(:status) { false }
|
33
|
+
|
34
|
+
it { is_expected.to eq(:service_unavailable) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fettle/checker'
|
3
|
+
|
4
|
+
module Fettle
|
5
|
+
RSpec.describe Checker do
|
6
|
+
describe '.run' do
|
7
|
+
subject(:result) { described_class.run(tag: tag) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow(Configuration).to receive(:checks).and_return(checks)
|
11
|
+
end
|
12
|
+
let(:checks) do
|
13
|
+
[ check ]
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:tag) { nil }
|
17
|
+
|
18
|
+
let(:check) do
|
19
|
+
Class.new do
|
20
|
+
def self.call
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when all checks are successful' do
|
27
|
+
it 'returns a successful CheckResult' do
|
28
|
+
expect(result).to be_an_instance_of(CheckResult)
|
29
|
+
expect(result.healthy?).to be_truthy
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'and the liveness tag is passed' do
|
33
|
+
let(:tag) { 'liveness' }
|
34
|
+
|
35
|
+
it 'returns a successful LivenessCheckResult' do
|
36
|
+
expect(result).to be_an_instance_of(LivenessCheckResult)
|
37
|
+
expect(result.healthy?).to be_truthy
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when a check fails' do
|
43
|
+
let(:check) do
|
44
|
+
Class.new do
|
45
|
+
def self.call
|
46
|
+
false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns a failed CheckResult' do
|
52
|
+
expect(result).to be_an_instance_of(CheckResult)
|
53
|
+
expect(result.healthy?).to be_falsey
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'and the liveness tag is passed' do
|
57
|
+
let(:tag) { 'liveness' }
|
58
|
+
|
59
|
+
it 'returns a failed LivenessCheckResult' do
|
60
|
+
expect(result).to be_an_instance_of(LivenessCheckResult)
|
61
|
+
expect(result.healthy?).to be_falsey
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when a check errors' do
|
67
|
+
let(:check) do
|
68
|
+
Class.new do
|
69
|
+
def self.call
|
70
|
+
raise
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns a failed CheckResult' do
|
76
|
+
expect(result).to be_an_instance_of(CheckResult)
|
77
|
+
expect(result.healthy?).to be_falsey
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'and the liveness tag is passed' do
|
81
|
+
let(:tag) { 'liveness' }
|
82
|
+
|
83
|
+
it 'returns a failed LivenessCheckResult' do
|
84
|
+
expect(result).to be_an_instance_of(LivenessCheckResult)
|
85
|
+
expect(result.healthy?).to be_falsey
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'fettle/checks/active_record_check'
|
3
|
+
|
4
|
+
module Fettle
|
5
|
+
module Checks
|
6
|
+
RSpec.describe ActiveRecordCheck do
|
7
|
+
describe '.call' do
|
8
|
+
subject(:check) { described_class.call }
|
9
|
+
|
10
|
+
context 'when a connection can be established' do
|
11
|
+
before do
|
12
|
+
allow(ActiveRecord::Base)
|
13
|
+
.to receive(:connected?).and_return(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it { is_expected.to be_truthy }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when a connection can not be established' do
|
20
|
+
before do
|
21
|
+
allow(ActiveRecord::Base)
|
22
|
+
.to receive(:connected?).and_return(false)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'raises a failed check error' do
|
26
|
+
expect { check }.to raise_error(
|
27
|
+
FailedCheck,
|
28
|
+
'Failed to establish database connection'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module Fettle
|
4
|
+
RSpec.describe Configuration do
|
5
|
+
describe '.configure' do
|
6
|
+
it 'yields itself' do
|
7
|
+
expect { |b| described_class.configure(&b) }
|
8
|
+
.to yield_with_args(described_class)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.add_check' do
|
13
|
+
after { described_class.clear_checks! }
|
14
|
+
|
15
|
+
context 'when a symbol is passed' do
|
16
|
+
context 'and references a valid check' do
|
17
|
+
it 'adds the check' do
|
18
|
+
described_class.add_check(:active_record)
|
19
|
+
|
20
|
+
expect(described_class.checks)
|
21
|
+
.to include(Checks::ActiveRecordCheck)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fettle/liveness_check_result'
|
3
|
+
|
4
|
+
module Fettle
|
5
|
+
RSpec.describe LivenessCheckResult do
|
6
|
+
describe '#healthy?' do
|
7
|
+
subject { described_class.new(status) }
|
8
|
+
|
9
|
+
let(:status) { true }
|
10
|
+
|
11
|
+
context 'for successful checks' do
|
12
|
+
it { is_expected.to be_healthy }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'for failed checks' do
|
16
|
+
let(:status) { false }
|
17
|
+
|
18
|
+
it { is_expected.to_not be_healthy }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#status_code' do
|
23
|
+
subject { described_class.new(status).status_code }
|
24
|
+
|
25
|
+
let(:status) { true }
|
26
|
+
|
27
|
+
context 'for successful checks' do
|
28
|
+
it { is_expected.to eq(:ok) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'for failed checks' do
|
32
|
+
let(:status) { false }
|
33
|
+
|
34
|
+
it { is_expected.to eq(:ok) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/rails_helper.rb
CHANGED
@@ -9,6 +9,8 @@ if Rails.env.production?
|
|
9
9
|
end
|
10
10
|
require 'rspec/rails'
|
11
11
|
|
12
|
+
require 'fettle'
|
13
|
+
|
12
14
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
13
15
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
14
16
|
# run as spec files by default. This means that files in spec/support that end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fettle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Kenny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -88,7 +88,12 @@ files:
|
|
88
88
|
- app/views/layouts/fettle/application.html.erb
|
89
89
|
- config/routes.rb
|
90
90
|
- lib/fettle.rb
|
91
|
+
- lib/fettle/check_result.rb
|
92
|
+
- lib/fettle/checker.rb
|
93
|
+
- lib/fettle/checks/active_record_check.rb
|
94
|
+
- lib/fettle/configuration.rb
|
91
95
|
- lib/fettle/engine.rb
|
96
|
+
- lib/fettle/liveness_check_result.rb
|
92
97
|
- lib/fettle/version.rb
|
93
98
|
- lib/tasks/fettle_tasks.rake
|
94
99
|
- spec/controllers/fettle/health_controller_spec.rb
|
@@ -125,6 +130,7 @@ files:
|
|
125
130
|
- spec/dummy/config/initializers/application_controller_renderer.rb
|
126
131
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
127
132
|
- spec/dummy/config/initializers/cookies_serializer.rb
|
133
|
+
- spec/dummy/config/initializers/fettle.rb
|
128
134
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
129
135
|
- spec/dummy/config/initializers/inflections.rb
|
130
136
|
- spec/dummy/config/initializers/mime_types.rb
|
@@ -146,6 +152,11 @@ files:
|
|
146
152
|
- spec/dummy/public/apple-touch-icon.png
|
147
153
|
- spec/dummy/public/favicon.ico
|
148
154
|
- spec/examples.txt
|
155
|
+
- spec/lib/fettle/check_result_spec.rb
|
156
|
+
- spec/lib/fettle/checker_spec.rb
|
157
|
+
- spec/lib/fettle/checks/active_record_check_spec.rb
|
158
|
+
- spec/lib/fettle/configuration_spec.rb
|
159
|
+
- spec/lib/fettle/liveness_check_result_spec.rb
|
149
160
|
- spec/rails_helper.rb
|
150
161
|
- spec/spec_helper.rb
|
151
162
|
homepage: https://git.thebeansgroup.com/utilities/fettle
|
@@ -205,6 +216,7 @@ test_files:
|
|
205
216
|
- spec/dummy/config/initializers/application_controller_renderer.rb
|
206
217
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
207
218
|
- spec/dummy/config/initializers/cookies_serializer.rb
|
219
|
+
- spec/dummy/config/initializers/fettle.rb
|
208
220
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
209
221
|
- spec/dummy/config/initializers/inflections.rb
|
210
222
|
- spec/dummy/config/initializers/mime_types.rb
|
@@ -228,5 +240,10 @@ test_files:
|
|
228
240
|
- spec/dummy/public/favicon.ico
|
229
241
|
- spec/dummy/Rakefile
|
230
242
|
- spec/examples.txt
|
243
|
+
- spec/lib/fettle/check_result_spec.rb
|
244
|
+
- spec/lib/fettle/checker_spec.rb
|
245
|
+
- spec/lib/fettle/checks/active_record_check_spec.rb
|
246
|
+
- spec/lib/fettle/configuration_spec.rb
|
247
|
+
- spec/lib/fettle/liveness_check_result_spec.rb
|
231
248
|
- spec/rails_helper.rb
|
232
249
|
- spec/spec_helper.rb
|