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

parse_cluster_applications_artifact_shared_examples.rb « clusters « services « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 466300017d98ea8b7c54fe2f6e6a6aad9da7338c (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true

RSpec.shared_examples 'parse cluster applications artifact' do |release_name|
  let(:application_class) { Clusters::Cluster::APPLICATIONS[release_name] }
  let(:cluster_application) { cluster.public_send("application_#{release_name}") }
  let(:file) { fixture_file_upload(Rails.root.join(fixture)) }
  let(:artifact) { create(:ci_job_artifact, :cluster_applications, job: job, file: file) }

  context 'release is missing' do
    let(:fixture) { "spec/fixtures/helm/helm_list_v2_#{release_name}_missing.json.gz" }

    context 'application does not exist' do
      it 'does not create or destroy an application' do
        expect do
          described_class.new(job, user).execute(artifact)
        end.not_to change(application_class, :count)
      end
    end

    context 'application exists' do
      before do
        create("clusters_applications_#{release_name}".to_sym, :installed, cluster: cluster)
      end

      it 'marks the application as uninstalled' do
        described_class.new(job, user).execute(artifact)

        cluster_application.reload
        expect(cluster_application).to be_uninstalled
      end
    end
  end

  context 'release is deployed' do
    let(:fixture) { "spec/fixtures/helm/helm_list_v2_#{release_name}_deployed.json.gz" }

    context 'application does not exist' do
      it 'creates an application and marks it as installed' do
        expect do
          described_class.new(job, user).execute(artifact)
        end.to change(application_class, :count)

        expect(cluster_application).to be_persisted
        expect(cluster_application).to be_externally_installed
      end
    end

    context 'application exists' do
      before do
        create("clusters_applications_#{release_name}".to_sym, :errored, cluster: cluster)
      end

      it 'marks the application as installed' do
        described_class.new(job, user).execute(artifact)

        expect(cluster_application).to be_externally_installed
      end
    end
  end

  context 'release is failed' do
    let(:fixture) { "spec/fixtures/helm/helm_list_v2_#{release_name}_failed.json.gz" }

    context 'application does not exist' do
      it 'creates an application and marks it as errored' do
        expect do
          described_class.new(job, user).execute(artifact)
        end.to change(application_class, :count)

        expect(cluster_application).to be_persisted
        expect(cluster_application).to be_errored
        expect(cluster_application.status_reason).to eq('Helm release failed to install')
      end
    end

    context 'application exists' do
      before do
        create("clusters_applications_#{release_name}".to_sym, :installed, cluster: cluster)
      end

      it 'marks the application as errored' do
        described_class.new(job, user).execute(artifact)

        expect(cluster_application).to be_errored
        expect(cluster_application.status_reason).to eq('Helm release failed to install')
      end
    end
  end
end