debian-mirror-gitlab/spec/lib/gitlab/prometheus/adapter_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
2.1 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Prometheus::Adapter do
2020-03-13 15:44:24 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:cluster, reload: true) { create(:cluster, :provided_by_user, environment_scope: '*', projects: [project]) }
2020-01-01 13:55:28 +05:30
2020-03-13 15:44:24 +05:30
subject { described_class.new(project, cluster) }
2018-03-27 19:54:05 +05:30
describe '#prometheus_adapter' do
2021-09-30 23:02:18 +05:30
context 'prometheus integration can execute queries' do
let(:prometheus_integration) { double(:prometheus_integration, can_query?: true) }
2018-03-27 19:54:05 +05:30
before do
2021-09-30 23:02:18 +05:30
allow(project).to receive(:find_or_initialize_integration).with('prometheus').and_return prometheus_integration
2018-03-27 19:54:05 +05:30
end
2021-09-30 23:02:18 +05:30
it 'return prometheus integration as prometheus adapter' do
expect(subject.prometheus_adapter).to eq(prometheus_integration)
2018-03-27 19:54:05 +05:30
end
2020-04-22 19:07:51 +05:30
context 'with cluster with prometheus available' do
2021-09-04 01:27:46 +05:30
let!(:prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
2020-04-22 19:07:51 +05:30
2021-09-30 23:02:18 +05:30
it 'returns prometheus integration' do
expect(subject.prometheus_adapter).to eq(prometheus_integration)
2020-04-22 19:07:51 +05:30
end
end
2018-03-27 19:54:05 +05:30
end
2021-09-30 23:02:18 +05:30
context "prometheus integration can't execute queries" do
let(:prometheus_integration) { double(:prometheus_integration, can_query?: false) }
2018-03-27 19:54:05 +05:30
2021-09-04 01:27:46 +05:30
before do
2021-09-30 23:02:18 +05:30
allow(project).to receive(:find_or_initialize_integration).with('prometheus').and_return prometheus_integration
2021-04-29 21:17:54 +05:30
end
2021-09-04 01:27:46 +05:30
context 'with cluster with prometheus disabled' do
let!(:prometheus) { create(:clusters_integrations_prometheus, enabled: false, cluster: cluster) }
2019-07-07 11:18:12 +05:30
it 'returns nil' do
expect(subject.prometheus_adapter).to be_nil
end
end
context 'with cluster with prometheus available' do
2021-09-04 01:27:46 +05:30
let!(:prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
2018-03-27 19:54:05 +05:30
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