query_variables_spec.rb 1.63 KB
Newer Older
1
2
3
4
5
6
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Prometheus::QueryVariables do
  describe '.call' do
7
    let(:project) { environment.project }
8
    let(:environment) { create(:environment) }
9
10
11
12
13
14
15
16
    let(:slug) { environment.slug }

    subject { described_class.call(environment) }

    it { is_expected.to include(ci_environment_slug: slug) }

    it do
      is_expected.to include(environment_filter:
17
                             %Q[container_name!="POD",environment="#{slug}"])
18
19
20
21
22
23
    end

    context 'without deployment platform' do
      it { is_expected.to include(kube_namespace: '') }
    end

24
    context 'with deployment platform' do
25
      context 'with project cluster' do
26
        let(:kube_namespace) { environment.deployment_namespace }
27

28
29
30
31
32
        before do
          create(:cluster, :project, :provided_by_user, projects: [project])
        end

        it { is_expected.to include(kube_namespace: kube_namespace) }
33
34
      end

35
36
37
38
39
40
      context 'with group cluster' do
        let(:cluster) { create(:cluster, :group, :provided_by_user, groups: [group]) }
        let(:group) { create(:group) }
        let(:project2) { create(:project) }
        let(:kube_namespace) { k8s_ns.namespace }

41
42
        let!(:k8s_ns) { create(:cluster_kubernetes_namespace, cluster: cluster, project: project, environment: environment) }
        let!(:k8s_ns2) { create(:cluster_kubernetes_namespace, cluster: cluster, project: project2, environment: environment) }
43
44
45
46
47
48
49
50

        before do
          group.projects << project
          group.projects << project2
        end

        it { is_expected.to include(kube_namespace: kube_namespace) }
      end
51
52
53
    end
  end
end