This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
forked from errbit/errbit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health_controller_spec.rb
52 lines (46 loc) · 1.68 KB
/
health_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
describe "Health", type: 'request' do
let(:errbit_app) { Fabricate(:app, api_key: 'APIKEY') }
describe "readiness" do
before do
if HealthController.instance_variable_defined? :@impatient_mongoid_client
HealthController.remove_instance_variable :@impatient_mongoid_client
end
end
it 'can let you know when the app is ready to receive requests' do
get '/health/readiness'
expect(response).to be_success
end
it 'can indicate if a check fails' do
expect(Errbit::Config).to receive(:mongo_url) {
'mongodb://localhost:27000'
}
get '/health/readiness'
expect(response).to be_error
parsed_response = JSON.parse(response.body)
expect(parsed_response['ok']).to eq false
expect(parsed_response['details'].first['check_name']).to eq 'mongo'
expect(parsed_response['details'].first['ok']).to eq false
expect(parsed_response['details'].first['error_details']).to_not be_nil
end
end
describe "liveness" do
it 'can let you know that the app is still alive' do
get '/health/liveness'
expect(response).to be_success
end
end
describe "api_key_tester" do
it 'will let you know when the api_key is not valid' do
get "/health/api-key-tester?api_key=garbagekey"
expect(response).to be_forbidden
parsed_response = JSON.parse(response.body)
expect(parsed_response['ok']).to eq false
end
it 'can let you know that the api_key is valid' do
get "/health/api-key-tester?api_key=#{errbit_app.api_key}"
expect(response).to be_success
parsed_response = JSON.parse(response.body)
expect(parsed_response['ok']).to eq true
end
end
end