2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-05 13:34:59 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-01-08 04:07:53 -05:00
|
|
|
describe Gitlab::Prometheus::Adapter do
|
2019-12-23 19:07:31 -05:00
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:cluster, reload: true) { create(:cluster, :provided_by_user, environment_scope: '*', projects: [project]) }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2019-12-23 19:07:31 -05:00
|
|
|
subject { described_class.new(project, cluster) }
|
2018-03-05 13:34:59 -05:00
|
|
|
|
|
|
|
describe '#prometheus_adapter' do
|
|
|
|
context 'prometheus service can execute queries' do
|
|
|
|
let(:prometheus_service) { double(:prometheus_service, can_query?: true) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'return prometheus service as prometheus adapter' do
|
|
|
|
expect(subject.prometheus_adapter).to eq(prometheus_service)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "prometheus service can't execute queries" do
|
|
|
|
let(:prometheus_service) { double(:prometheus_service, can_query?: false) }
|
|
|
|
|
2019-02-14 18:43:44 -05:00
|
|
|
context 'with cluster with prometheus not available' do
|
2019-02-14 18:41:10 -05:00
|
|
|
let!(:prometheus) { create(:clusters_applications_prometheus, :installable, cluster: cluster) }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(subject.prometheus_adapter).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-14 18:43:44 -05:00
|
|
|
context 'with cluster with prometheus available' do
|
2018-03-05 13:34:59 -05:00
|
|
|
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
|
|
|
|
|
|
|
|
it 'returns application handling all environments' do
|
|
|
|
expect(subject.prometheus_adapter).to eq(prometheus)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with cluster without prometheus installed' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(subject.prometheus_adapter).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|