diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-06 15:40:03 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-06 15:40:03 +0300 |
commit | c7a1da800ff6fa16db5de796a8f8d715ddd3b582 (patch) | |
tree | 3db1bd3488130c4fe3eacc9ce947dc7898c9f92f /spec | |
parent | c0a66dbd2dd8b716e809938d20e7655d84595176 (diff) |
Explicitly require format.json in prometheus_controller
+ add missing prometheus_controller tests!
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/prometheus_controller_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/controllers/projects/prometheus_controller_spec.rb b/spec/controllers/projects/prometheus_controller_spec.rb new file mode 100644 index 00000000000..5e57b19e042 --- /dev/null +++ b/spec/controllers/projects/prometheus_controller_spec.rb @@ -0,0 +1,60 @@ +require('spec_helper') + +describe Projects::PrometheusController do + let(:user) { create(:user) } + let!(:project) { create(:empty_project) } + + let(:prometheus_service) { double('prometheus_service') } + + before do + allow(controller).to receive(:project).and_return(project) + allow(project).to receive(:monitoring_service).and_return(prometheus_service) + + project.add_master(user) + sign_in(user) + end + + describe 'GET #active_metrics' do + context 'when prometheus metrics are enabled' do + before do + allow(prometheus_service).to receive(:reactive_query) + end + + context 'when data is not present' do + it 'returns no content response' do + get :active_metrics, project_params(format: :json) + + expect(response).to have_http_status(204) + end + end + + context 'when data is available' do + let(:sample_response) { { some_data: 1 } } + + before do + allow(prometheus_service).to receive(:reactive_query).with(Gitlab::Prometheus::Queries::MatchedMetricsQuery.name) + .and_return(sample_response) + end + + it 'returns no content response' do + get :active_metrics, project_params(format: :json) + + expect(response).to have_http_status(200) + expect(json_response).to eq(sample_response.deep_stringify_keys) + end + end + + context 'when requesting non json response' do + it 'returns not found response' do + get :active_metrics, project_params + + expect(response).to have_http_status(404) + end + end + end + end + + def project_params(opts = {}) + opts.reverse_merge(namespace_id: project.namespace, project_id: project) + end +end
\ No newline at end of file |