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