wellness 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc67d265fe3b43ff86c235e0317c32e20ccd0971
4
- data.tar.gz: d7a96511cebbaeee9926489760d3bcf7667227f9
3
+ metadata.gz: 92603932dbccf29905140576d88df9122d0f6b5b
4
+ data.tar.gz: 67903699abe0a4d32ec6a59110c51dfea511273b
5
5
  SHA512:
6
- metadata.gz: ee1f255adf40cdd1f3ba90a31e28ae4f8b0fb5c9b6e9d31eb23f41c9646e71c0d53cf415ba8d9170b537a96eaea7c44fce3214aebab15c71bba0fe491b02cda3
7
- data.tar.gz: 368f138e36a57ae792b92f9d7d6d2d934033a64219aef4686c99945c93f115bf982a096d54f09eef63b76207028d162288eb24f4497aa6f0d94e6ba003e984d4
6
+ metadata.gz: 055987a1113450d41b444c847a86ae88302873be09728810cff488d53e43abdb30081b2fc92505c8cdb71c8d0ff70433305169f9f16077a6920d6c9c15ed423b
7
+ data.tar.gz: 6d568347a584ed37b388593e16442e23f2dd4574a0b383290a6820d4958de20115cdc02480e4d0f75866fe83bd93b2c576c0bf1cd7d06047e6347ca69db99be6
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module Wellness
2
4
 
3
5
  # This is to be put into the Rack environment.
@@ -16,24 +18,25 @@ module Wellness
16
18
  def call(env)
17
19
  case env['PATH_INFO']
18
20
  when @health_status_path
19
- health_status(env)
21
+ health_status_check
20
22
  when @health_details_path
21
- health_details(env)
23
+ health_details_check
22
24
  else
23
25
  @app.call(env)
24
26
  end
25
27
  end
26
28
 
27
- def health_status(env)
29
+ private
30
+
31
+ def health_status_check
28
32
  if @system.check
29
33
  [200, {'Content-Type' => 'text/json'}, [{status: 'HEALTHY'}.to_json]]
30
34
  else
31
35
  [500, {'Content-Type' => 'text/json'}, [{status: 'UNHEALTHY'}.to_json]]
32
36
  end
33
-
34
37
  end
35
38
 
36
- def health_details(env)
39
+ def health_details_check
37
40
  if @system.check
38
41
  [200, {'Content-Type' => 'text/json'}, [@system.to_json]]
39
42
  else
@@ -1,3 +1,3 @@
1
1
  module Wellness
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'rspec'
2
2
  require 'wellness'
3
+
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wellness::Middleware do
4
+ let(:app) { double('Application', call: true) }
5
+ let(:system) { Wellness::System.new('testing') }
6
+ let(:middleware) { Wellness::Middleware.new(app, system) }
7
+
8
+ class PassingMockService < Wellness::Services::Base
9
+ def check
10
+ passed_check
11
+ {
12
+ 'status' => 'HEALTHY',
13
+ 'details' => {}
14
+ }
15
+ end
16
+ end
17
+
18
+ class FailingMockService < Wellness::Services::Base
19
+ def check
20
+ failed_check
21
+ {
22
+ 'status' => 'UNHEALTHY',
23
+ 'details' => {}
24
+ }
25
+ end
26
+ end
27
+
28
+ describe '#call' do
29
+ context 'when the PATH_INFO is the health status path' do
30
+ let(:env) { { 'PATH_INFO' => '/health/status' } }
31
+ subject { middleware.call(env) }
32
+
33
+ context 'when the system check is unhealthy' do
34
+ before { system.stub(check: false) }
35
+
36
+ it 'returns a 500 status' do
37
+ expect(subject[0]).to eq(500)
38
+ end
39
+
40
+ it 'returns a json content type' do
41
+ expect(subject[1]).to eq({ 'Content-Type' => 'text/json' })
42
+ end
43
+
44
+ it 'returns UNHEALTHY' do
45
+ data = JSON.parse(subject[2].first)
46
+ expect(data).to eq({ 'status' => 'UNHEALTHY' })
47
+ end
48
+ end
49
+
50
+ context 'when the system check is healthy' do
51
+ before { system.stub(check: true) }
52
+
53
+ it 'returns a 200 status' do
54
+ expect(subject[0]).to eq(200)
55
+ end
56
+
57
+ it 'returns a json content type' do
58
+ expect(subject[1]).to eq({ 'Content-Type' => 'text/json' })
59
+ end
60
+
61
+ it 'returns HEALTHY' do
62
+ data = JSON.parse(subject[2].first)
63
+ expect(data).to eq({ 'status' => 'HEALTHY' })
64
+ end
65
+ end
66
+ end
67
+
68
+ context 'when the PATH_INFO is the health details path' do
69
+ let(:env) { { 'PATH_INFO' => '/health/details' } }
70
+ subject { middleware.call(env) }
71
+
72
+ context 'when the system check is unhealthy' do
73
+ before do
74
+ system.add_service('mock service', FailingMockService.new)
75
+ end
76
+
77
+ it 'returns a 500 status' do
78
+ expect(subject[0]).to eq(500)
79
+ end
80
+
81
+ it 'returns a json content type' do
82
+ expect(subject[1]).to eq({ 'Content-Type' => 'text/json' })
83
+ end
84
+
85
+ it 'returns UNHEALTHY' do
86
+ expected = {
87
+ 'status' => 'UNHEALTHY',
88
+ 'details' => {},
89
+ 'dependencies' => {
90
+ 'mock service' => {
91
+ 'status' => 'UNHEALTHY',
92
+ 'details' => {}
93
+ }
94
+ }
95
+ }
96
+
97
+ data = JSON.parse(subject[2].first)
98
+ expect(data).to eq(expected)
99
+ end
100
+ end
101
+ context 'when the system check is healthy' do
102
+ before do
103
+ system.add_service('mock service', PassingMockService.new)
104
+ end
105
+
106
+ it 'returns a 200 status' do
107
+ expect(subject[0]).to eq(200)
108
+ end
109
+
110
+ it 'returns a json content type' do
111
+ expect(subject[1]).to eq({ 'Content-Type' => 'text/json' })
112
+ end
113
+
114
+ it 'returns UNHEALTHY' do
115
+ expected = {
116
+ 'status' => 'HEALTHY',
117
+ 'details' => {},
118
+ 'dependencies' => {
119
+ 'mock service' => {
120
+ 'status' => 'HEALTHY',
121
+ 'details' => {}
122
+ }
123
+ }
124
+ }
125
+
126
+ data = JSON.parse(subject[2].first)
127
+ expect(data).to eq(expected)
128
+ end
129
+ end
130
+ end
131
+
132
+ context 'when the PATH_INFO is /who/cares' do
133
+ let(:env) { { 'PATH_INFO' => '/who/cares' } }
134
+
135
+ it 'passes the request to the next rack' do
136
+ middleware.call(env)
137
+ expect(app).to have_received(:call).with(env)
138
+ end
139
+ end
140
+ end
141
+ end
@@ -4,6 +4,26 @@ describe Wellness::System do
4
4
  let(:name) { 'testing-app' }
5
5
  let(:system) { described_class.new(name) }
6
6
 
7
+ class PassingMockService < Wellness::Services::Base
8
+ def check
9
+ passed_check
10
+ {
11
+ 'status' => 'HEALTHY',
12
+ 'details' => {}
13
+ }
14
+ end
15
+ end
16
+
17
+ class FailingMockService < Wellness::Services::Base
18
+ def check
19
+ failed_check
20
+ {
21
+ 'status' => 'UNHEALTHY',
22
+ 'details' => {}
23
+ }
24
+ end
25
+ end
26
+
7
27
  describe '#name' do
8
28
  subject { system.name }
9
29
  it 'equals "testing-app"' do
@@ -12,7 +32,7 @@ describe Wellness::System do
12
32
  end
13
33
 
14
34
  describe '#add_service' do
15
- let(:service) { double('Service') }
35
+ let(:service) { double('Service') }
16
36
  subject { system.add_service('foo', service) }
17
37
 
18
38
  it 'adds the service to the system' do
@@ -21,7 +41,7 @@ describe Wellness::System do
21
41
  end
22
42
 
23
43
  describe '#remove_service' do
24
- let(:service) { double('Service') }
44
+ let(:service) { double('Service') }
25
45
  subject { system.remove_service('foo') }
26
46
  before { system.add_service('foo', service) }
27
47
  it 'removes the service from the system' do
@@ -29,4 +49,52 @@ describe Wellness::System do
29
49
  end
30
50
  end
31
51
 
52
+ describe '#check' do
53
+ subject { system.check }
54
+
55
+ context 'when no services are registered' do
56
+ it 'returns true' do
57
+ expect(subject).to be_true
58
+ end
59
+ end
60
+
61
+ context 'when a passing service is registered' do
62
+ before { system.add_service('passing', PassingMockService.new) }
63
+
64
+ it 'returns true' do
65
+ expect(subject).to be_true
66
+ end
67
+ end
68
+
69
+ context 'when a failing service is registered' do
70
+ before { system.add_service('failing', FailingMockService.new) }
71
+
72
+ it 'returns false' do
73
+ expect(subject).to be_false
74
+ end
75
+ end
76
+
77
+ context 'when one service is failing and the other is passing' do
78
+ before do
79
+ system.add_service('passing', PassingMockService.new)
80
+ system.add_service('failing', FailingMockService.new)
81
+ end
82
+
83
+ it 'returns false' do
84
+ expect(subject).to be_false
85
+ end
86
+ end
87
+
88
+ context 'when all services are passing' do
89
+ before do
90
+ system.add_service('passing one', PassingMockService.new)
91
+ system.add_service('passing two', PassingMockService.new)
92
+ end
93
+
94
+ it 'returns true' do
95
+ expect(subject).to be_true
96
+ end
97
+ end
98
+ end
99
+
32
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wellness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Johnston
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
+ - .rspec
63
64
  - .ruby-gemset
64
65
  - .ruby-version
65
66
  - Gemfile
@@ -76,7 +77,7 @@ files:
76
77
  - lib/wellness/system.rb
77
78
  - lib/wellness/version.rb
78
79
  - spec/spec_helper.rb
79
- - spec/wellness/checker_spec.rb
80
+ - spec/wellness/middleware_spec.rb
80
81
  - spec/wellness/system_spec.rb
81
82
  - wellness.gemspec
82
83
  homepage: https://github.com/warmwaffles/wellness
@@ -105,5 +106,5 @@ specification_version: 4
105
106
  summary: A rack middleware health check
106
107
  test_files:
107
108
  - spec/spec_helper.rb
108
- - spec/wellness/checker_spec.rb
109
+ - spec/wellness/middleware_spec.rb
109
110
  - spec/wellness/system_spec.rb
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Wellness::Middleware do
4
- pending
5
- end