2017-06-06 12:40:03 +00:00
|
|
|
require('spec_helper')
|
|
|
|
|
|
|
|
describe Projects::PrometheusController do
|
|
|
|
let(:user) { create(:user) }
|
2017-08-02 19:55:11 +00:00
|
|
|
let!(:project) { create(:project) }
|
2017-06-06 12:40:03 +00:00
|
|
|
|
|
|
|
let(:prometheus_service) { double('prometheus_service') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:project).and_return(project)
|
2017-06-16 18:48:34 +00:00
|
|
|
allow(project).to receive(:prometheus_service).and_return(prometheus_service)
|
2017-06-06 12:40:03 +00:00
|
|
|
|
|
|
|
project.add_master(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #active_metrics' do
|
|
|
|
context 'when prometheus metrics are enabled' do
|
|
|
|
context 'when data is not present' do
|
2017-06-07 00:36:59 +00:00
|
|
|
before do
|
|
|
|
allow(prometheus_service).to receive(:matched_metrics).and_return({})
|
|
|
|
end
|
|
|
|
|
2017-06-06 12:40:03 +00:00
|
|
|
it 'returns no content response' do
|
|
|
|
get :active_metrics, project_params(format: :json)
|
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2017-06-06 12:40:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when data is available' do
|
|
|
|
let(:sample_response) { { some_data: 1 } }
|
|
|
|
|
|
|
|
before do
|
2017-06-07 00:36:59 +00:00
|
|
|
allow(prometheus_service).to receive(:matched_metrics).and_return(sample_response)
|
2017-06-06 12:40:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no content response' do
|
|
|
|
get :active_metrics, project_params(format: :json)
|
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-06 12:40:03 +00:00
|
|
|
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
|
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-06-06 12:40:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_params(opts = {})
|
|
|
|
opts.reverse_merge(namespace_id: project.namespace, project_id: project)
|
|
|
|
end
|
2017-06-06 14:07:33 +00:00
|
|
|
end
|