diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 09:07:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 09:07:53 +0000 |
commit | a821bd6ad17e304ca93838a411410a44ee9cff9f (patch) | |
tree | 5444ab20a2f8b22db736a93c5c376928dde8e450 /spec/lib | |
parent | f6e985dba4d0f5b1ede95e9174d30dd6a8bedf0d (diff) | |
download | gitlab-ce-a821bd6ad17e304ca93838a411410a44ee9cff9f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/prometheus/adapter_spec.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/lib/gitlab/prometheus/adapter_spec.rb b/spec/lib/gitlab/prometheus/adapter_spec.rb new file mode 100644 index 00000000000..202bf65f92b --- /dev/null +++ b/spec/lib/gitlab/prometheus/adapter_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Prometheus::Adapter do + let_it_be(:project) { create(:project) } + let_it_be(:cluster, reload: true) { create(:cluster, :provided_by_user, environment_scope: '*', projects: [project]) } + + subject { described_class.new(project, cluster) } + + 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) } + + context 'with cluster with prometheus not available' do + let!(:prometheus) { create(:clusters_applications_prometheus, :installable, cluster: cluster) } + + it 'returns nil' do + expect(subject.prometheus_adapter).to be_nil + end + end + + context 'with cluster with prometheus available' do + 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 |