health_check_toolbox 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +84 -0
  3. data/Rakefile +6 -0
  4. data/config/locales/en.yml +6 -0
  5. data/config/routes.rb +3 -0
  6. data/lib/health_check_toolbox.rb +19 -0
  7. data/lib/health_check_toolbox/config.rb +39 -0
  8. data/lib/health_check_toolbox/engine.rb +6 -0
  9. data/lib/health_check_toolbox/health_check_routes.rb +15 -0
  10. data/lib/health_check_toolbox/health_controller.rb +18 -0
  11. data/lib/health_check_toolbox/services/base_health_check.rb +21 -0
  12. data/lib/health_check_toolbox/services/database.rb +22 -0
  13. data/lib/health_check_toolbox/services/redis_service.rb +21 -0
  14. data/lib/health_check_toolbox/services/rest_services.rb +74 -0
  15. data/lib/health_check_toolbox/services/wso2.rb +21 -0
  16. data/lib/health_check_toolbox/status_manager.rb +49 -0
  17. data/lib/health_check_toolbox/version.rb +5 -0
  18. data/spec/dummy/Rakefile +9 -0
  19. data/spec/dummy/bin/bundle +5 -0
  20. data/spec/dummy/bin/rails +6 -0
  21. data/spec/dummy/bin/rake +6 -0
  22. data/spec/dummy/bin/setup +37 -0
  23. data/spec/dummy/bin/update +32 -0
  24. data/spec/dummy/bin/yarn +13 -0
  25. data/spec/dummy/config.ru +7 -0
  26. data/spec/dummy/config/application.rb +14 -0
  27. data/spec/dummy/config/boot.rb +7 -0
  28. data/spec/dummy/config/cable.yml +10 -0
  29. data/spec/dummy/config/database.yml +16 -0
  30. data/spec/dummy/config/environment.rb +5 -0
  31. data/spec/dummy/config/environments/development.rb +32 -0
  32. data/spec/dummy/config/environments/production.rb +26 -0
  33. data/spec/dummy/config/environments/test.rb +25 -0
  34. data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
  35. data/spec/dummy/config/initializers/assets.rb +5 -0
  36. data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
  37. data/spec/dummy/config/initializers/content_security_policy.rb +1 -0
  38. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  39. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -0
  40. data/spec/dummy/config/initializers/inflections.rb +1 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +5 -0
  43. data/spec/dummy/config/puma.rb +10 -0
  44. data/spec/dummy/config/routes.rb +4 -0
  45. data/spec/dummy/config/spring.rb +8 -0
  46. data/spec/dummy/config/storage.yml +8 -0
  47. data/spec/dummy/package.json +5 -0
  48. data/spec/health_check_toolbox/config_spec.rb +87 -0
  49. data/spec/health_check_toolbox/health_controller_spec.rb +47 -0
  50. data/spec/health_check_toolbox/services/database_spec.rb +19 -0
  51. data/spec/health_check_toolbox/services/redis_service_spec.rb +27 -0
  52. data/spec/health_check_toolbox/services/rest_services_spec.rb +45 -0
  53. data/spec/health_check_toolbox/services/wso2_spec.rb +26 -0
  54. data/spec/health_check_toolbox/status_manager_spec.rb +78 -0
  55. data/spec/health_check_toolbox_spec.rb +22 -0
  56. data/spec/spec_helper.rb +20 -0
  57. metadata +263 -0
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe HealthCheckToolbox::HealthController, type: :controller do
6
+ let(:body) { JSON.parse(response.body) }
7
+
8
+ describe 'GET' do
9
+ describe '#service_status' do
10
+ let(:version) { '1.3.0' }
11
+
12
+ before do
13
+ allow(File).to receive(:read).
14
+ with('.version').and_return("#{version}\n")
15
+
16
+ get :service_status
17
+ end
18
+
19
+ it { expect(body['ok']).to be_truthy }
20
+ it { expect(body['version']).not_to be_nil }
21
+ it { expect(body['version']).to eq(version) }
22
+ end
23
+
24
+ describe '#health_check' do
25
+ let(:status) do
26
+ {
27
+ 'status_1' => 'redis_service:ok',
28
+ 'status_2' => 'database:ok'
29
+ }
30
+ end
31
+
32
+ before do
33
+ allow(HealthCheckToolbox::Config).
34
+ to receive(:services_status).and_return(status)
35
+
36
+ get :health_check
37
+ end
38
+
39
+ it { expect(body).to have_key('timestamp') }
40
+ it { expect(body['timestamp']).not_to be_nil }
41
+ it { expect(body).to have_key('health_check') }
42
+ it { expect(body['health_check']).not_to be_empty }
43
+ it { expect(body['health_check'].first).to have_key('status_1') }
44
+ it { expect(body['health_check'].first).to have_key('status_2') }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe HealthCheckToolbox::Services::Database do
6
+ subject { described_class.new.try_connect }
7
+
8
+ describe '#try_connect' do
9
+ context 'when database is up' do
10
+ it { is_expected.to eq('ok') }
11
+ end
12
+
13
+ context 'when database is down' do
14
+ before { allow(ActiveRecord::Base).to receive(:connection) }
15
+
16
+ it { is_expected.to eq('erro') }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe HealthCheckToolbox::Services::RedisService do
6
+ before { allow(Redis).to receive(:new).send(return_method, method_response) }
7
+
8
+ subject do
9
+ described_class.new.try_connect
10
+ end
11
+
12
+ describe '#try_connect' do
13
+ context 'when redis is up' do
14
+ let(:method_response) { double(ping: 'PONG') }
15
+ let(:return_method) { :and_return }
16
+
17
+ it { is_expected.to eq('ok') }
18
+ end
19
+
20
+ context 'when redis is down' do
21
+ let(:method_response) { double(ping: 'BOOM') }
22
+ let(:return_method) { :and_raise }
23
+
24
+ it { is_expected.to eq('erro') }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe HealthCheckToolbox::Services::RestServices do
6
+ let(:rest_services) { described_class.new(args, block).services }
7
+ let(:args) { [] }
8
+ let(:return_method) { :and_return }
9
+ let(:method_response) { nil }
10
+ let(:block) do
11
+ proc do
12
+ file_storage_service 'http://google.com'
13
+ asset_classification_service 'http://guide.com.br'
14
+ end
15
+ end
16
+
17
+ before do
18
+ allow(Wso2Toolbox::TokenManager).to receive(:generate_token)
19
+ allow(RestClient).to receive(:get).send(return_method, method_response)
20
+ end
21
+
22
+ subject { rest_services.collect(&:try_connect) }
23
+
24
+ describe '#try_connect' do
25
+ context 'when all services is up' do
26
+ context 'and returning http code 200' do
27
+ let(:method_response) { double(code: 200) }
28
+
29
+ it { is_expected.to all(eq('ok')) }
30
+ end
31
+
32
+ context 'and returning http code 500' do
33
+ let(:method_response) { double(code: 500) }
34
+
35
+ it { is_expected.to all(eq('erro')) }
36
+ end
37
+ end
38
+
39
+ context 'when all services is down' do
40
+ let(:return_method) { :and_raise }
41
+
42
+ it { is_expected.to all(eq('erro')) }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe HealthCheckToolbox::Services::Wso2 do
6
+ subject do
7
+ described_class.new.try_connect
8
+ end
9
+
10
+ describe '#try_connect' do
11
+ context 'when wso2 is up' do
12
+ before { allow(Wso2Toolbox::TokenManager).to receive(:generate_token) }
13
+
14
+ it { is_expected.to eq('ok') }
15
+ end
16
+
17
+ context 'when wso2 is down' do
18
+ before do
19
+ allow(Wso2Toolbox::TokenManager).to receive(:generate_token).
20
+ and_raise('boom')
21
+ end
22
+
23
+ it { is_expected.to eq('erro') }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe HealthCheckToolbox::StatusManager do
6
+ describe '.generate' do
7
+ let(:default_services) do
8
+ [
9
+ HealthCheckToolbox::Services::RedisService.new([redis], nil),
10
+ HealthCheckToolbox::Services::Database.new([database], nil)
11
+ ]
12
+ end
13
+ let(:database) { true }
14
+ let(:redis) { true }
15
+ let(:service_response) { 'ok' }
16
+
17
+ before do
18
+ allow_any_instance_of(HealthCheckToolbox::Services::RedisService).
19
+ to receive(:try_connect).and_return(service_response)
20
+ allow_any_instance_of(HealthCheckToolbox::Services::Database).
21
+ to receive(:try_connect).and_return(service_response)
22
+ end
23
+
24
+ subject(:status) { described_class.generate(default_services) }
25
+
26
+ context 'when status are ok' do
27
+ it do
28
+ expect(status[:status_1]).to eq("redis_service:#{service_response}")
29
+ end
30
+ it { expect(status[:status_2]).to eq("database:#{service_response}") }
31
+ end
32
+
33
+ context 'when status has error' do
34
+ let(:service_response) { 'erro' }
35
+
36
+ it do
37
+ expect(status[:status_1]).to eq("redis_service:#{service_response}")
38
+ end
39
+ it { expect(status[:status_2]).to eq("database:#{service_response}") }
40
+ end
41
+
42
+ context 'with rest_services block', test: true do
43
+ let(:services) { [default_services, @rest_services].flatten }
44
+ let(:block) do
45
+ proc do
46
+ file_storage_service 'http://google.com'
47
+ asset_classification_service 'http://guide.com.br'
48
+ end
49
+ end
50
+
51
+ before do
52
+ @rest_services = HealthCheckToolbox::Services::RestServices.new(
53
+ [], block
54
+ )
55
+
56
+ allow_any_instance_of(
57
+ HealthCheckToolbox::Services::FileStorageService
58
+ ).to receive(:try_connect).and_return(service_response)
59
+
60
+ allow_any_instance_of(
61
+ HealthCheckToolbox::Services::AssetClassificationService
62
+ ).to receive(:try_connect).and_return(service_response)
63
+ end
64
+
65
+ subject(:status) { described_class.generate(services) }
66
+
67
+ it do
68
+ expect(status[:status_3]).
69
+ to eq("file_storage_service:#{service_response}")
70
+ end
71
+
72
+ it do
73
+ expect(status[:status_4]).
74
+ to eq("asset_classification_service:#{service_response}")
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe HealthCheckToolbox do
6
+ it 'has a version number' do
7
+ expect(HealthCheckToolbox::VERSION).not_to be nil
8
+ end
9
+
10
+ describe '.setup' do
11
+ let(:config) { double(instance_eval: true) }
12
+ let(:block) { proc { redis_service true } }
13
+
14
+ before do
15
+ allow(HealthCheckToolbox::Config).to receive(:new).and_return(config)
16
+ end
17
+
18
+ subject { described_class.setup(&block) }
19
+
20
+ it { is_expected.to be_truthy }
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+ require File.expand_path('dummy/config/environment.rb', __dir__)
5
+ require 'bundler/setup'
6
+ require 'rspec/rails'
7
+ require 'health_check_toolbox'
8
+ require 'pry-byebug'
9
+
10
+ # Load support files
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ RSpec.configure do |config|
14
+ config.example_status_persistence_file_path = '.rspec_status'
15
+ config.disable_monkey_patching!
16
+
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,263 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: health_check_toolbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tatiane Guedes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: wso2_toolbox
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - t.coleto@prestserv.guide.com.br
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - README.md
147
+ - Rakefile
148
+ - config/locales/en.yml
149
+ - config/routes.rb
150
+ - lib/health_check_toolbox.rb
151
+ - lib/health_check_toolbox/config.rb
152
+ - lib/health_check_toolbox/engine.rb
153
+ - lib/health_check_toolbox/health_check_routes.rb
154
+ - lib/health_check_toolbox/health_controller.rb
155
+ - lib/health_check_toolbox/services/base_health_check.rb
156
+ - lib/health_check_toolbox/services/database.rb
157
+ - lib/health_check_toolbox/services/redis_service.rb
158
+ - lib/health_check_toolbox/services/rest_services.rb
159
+ - lib/health_check_toolbox/services/wso2.rb
160
+ - lib/health_check_toolbox/status_manager.rb
161
+ - lib/health_check_toolbox/version.rb
162
+ - spec/dummy/Rakefile
163
+ - spec/dummy/bin/bundle
164
+ - spec/dummy/bin/rails
165
+ - spec/dummy/bin/rake
166
+ - spec/dummy/bin/setup
167
+ - spec/dummy/bin/update
168
+ - spec/dummy/bin/yarn
169
+ - spec/dummy/config.ru
170
+ - spec/dummy/config/application.rb
171
+ - spec/dummy/config/boot.rb
172
+ - spec/dummy/config/cable.yml
173
+ - spec/dummy/config/database.yml
174
+ - spec/dummy/config/environment.rb
175
+ - spec/dummy/config/environments/development.rb
176
+ - spec/dummy/config/environments/production.rb
177
+ - spec/dummy/config/environments/test.rb
178
+ - spec/dummy/config/initializers/application_controller_renderer.rb
179
+ - spec/dummy/config/initializers/assets.rb
180
+ - spec/dummy/config/initializers/backtrace_silencers.rb
181
+ - spec/dummy/config/initializers/content_security_policy.rb
182
+ - spec/dummy/config/initializers/cookies_serializer.rb
183
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
184
+ - spec/dummy/config/initializers/inflections.rb
185
+ - spec/dummy/config/initializers/mime_types.rb
186
+ - spec/dummy/config/initializers/wrap_parameters.rb
187
+ - spec/dummy/config/puma.rb
188
+ - spec/dummy/config/routes.rb
189
+ - spec/dummy/config/spring.rb
190
+ - spec/dummy/config/storage.yml
191
+ - spec/dummy/package.json
192
+ - spec/health_check_toolbox/config_spec.rb
193
+ - spec/health_check_toolbox/health_controller_spec.rb
194
+ - spec/health_check_toolbox/services/database_spec.rb
195
+ - spec/health_check_toolbox/services/redis_service_spec.rb
196
+ - spec/health_check_toolbox/services/rest_services_spec.rb
197
+ - spec/health_check_toolbox/services/wso2_spec.rb
198
+ - spec/health_check_toolbox/status_manager_spec.rb
199
+ - spec/health_check_toolbox_spec.rb
200
+ - spec/spec_helper.rb
201
+ homepage: http://bitbucket.org/guideinvestimentos/health_check_toolbox
202
+ licenses: []
203
+ metadata: {}
204
+ post_install_message:
205
+ rdoc_options: []
206
+ require_paths:
207
+ - lib
208
+ required_ruby_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ requirements: []
219
+ rubyforge_project:
220
+ rubygems_version: 2.7.7
221
+ signing_key:
222
+ specification_version: 4
223
+ summary: Tools to provide service status routes and health check
224
+ test_files:
225
+ - spec/dummy/bin/rake
226
+ - spec/dummy/bin/yarn
227
+ - spec/dummy/bin/bundle
228
+ - spec/dummy/bin/rails
229
+ - spec/dummy/bin/update
230
+ - spec/dummy/bin/setup
231
+ - spec/dummy/package.json
232
+ - spec/dummy/config.ru
233
+ - spec/dummy/config/cable.yml
234
+ - spec/dummy/config/routes.rb
235
+ - spec/dummy/config/environments/development.rb
236
+ - spec/dummy/config/environments/test.rb
237
+ - spec/dummy/config/environments/production.rb
238
+ - spec/dummy/config/initializers/backtrace_silencers.rb
239
+ - spec/dummy/config/initializers/inflections.rb
240
+ - spec/dummy/config/initializers/assets.rb
241
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
242
+ - spec/dummy/config/initializers/mime_types.rb
243
+ - spec/dummy/config/initializers/application_controller_renderer.rb
244
+ - spec/dummy/config/initializers/cookies_serializer.rb
245
+ - spec/dummy/config/initializers/content_security_policy.rb
246
+ - spec/dummy/config/initializers/wrap_parameters.rb
247
+ - spec/dummy/config/puma.rb
248
+ - spec/dummy/config/application.rb
249
+ - spec/dummy/config/spring.rb
250
+ - spec/dummy/config/environment.rb
251
+ - spec/dummy/config/boot.rb
252
+ - spec/dummy/config/database.yml
253
+ - spec/dummy/config/storage.yml
254
+ - spec/dummy/Rakefile
255
+ - spec/health_check_toolbox/health_controller_spec.rb
256
+ - spec/health_check_toolbox/config_spec.rb
257
+ - spec/health_check_toolbox/services/database_spec.rb
258
+ - spec/health_check_toolbox/services/wso2_spec.rb
259
+ - spec/health_check_toolbox/services/rest_services_spec.rb
260
+ - spec/health_check_toolbox/services/redis_service_spec.rb
261
+ - spec/health_check_toolbox/status_manager_spec.rb
262
+ - spec/health_check_toolbox_spec.rb
263
+ - spec/spec_helper.rb