Welcome to mirror list, hosted at ThFree Co, Russian Federation.

activate_integration_worker_spec.rb « applications « clusters « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ecb49be5a4b9cdce77b22173808206142fe7d683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Clusters::Applications::ActivateIntegrationWorker, '#perform' do
  context 'when cluster exists' do
    describe 'prometheus integration' do
      let(:integration_name) { 'prometheus' }

      before do
        create(:clusters_integrations_prometheus, cluster: cluster)
      end

      context 'with cluster type: group' do
        let(:group) { create(:group) }
        let(:project) { create(:project, group: group) }
        let(:cluster) { create(:cluster_for_group, groups: [group]) }

        it 'ensures Prometheus integration is activated' do
          expect { described_class.new.perform(cluster.id, integration_name) }
            .to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
        end
      end

      context 'with cluster type: project' do
        let(:project) { create(:project) }
        let(:cluster) { create(:cluster, projects: [project]) }

        it 'ensures Prometheus integration is activated' do
          expect { described_class.new.perform(cluster.id, integration_name) }
            .to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
        end
      end

      context 'with cluster type: instance' do
        let(:project) { create(:project) }
        let(:cluster) { create(:cluster, :instance) }

        it 'ensures Prometheus integration is activated' do
          expect { described_class.new.perform(cluster.id, integration_name) }
            .to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
        end

        context 'when using the old worker class' do
          let(:described_class) { Clusters::Applications::ActivateServiceWorker }

          it 'ensures Prometheus integration is activated' do
            expect { described_class.new.perform(cluster.id, integration_name) }
              .to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
          end
        end
      end
    end
  end

  context 'when cluster does not exist' do
    it 'does not raise Record Not Found error' do
      expect { described_class.new.perform(0, 'ignored in this context') }.not_to raise_error
    end
  end
end