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

schedule_installation_service_spec.rb « applications « clusters « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 473dbcbb6927f800169d3cab2c358c44cf77c2bd (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
require 'spec_helper'

describe Clusters::Applications::ScheduleInstallationService do
  def count_scheduled
    application_class&.with_status(:scheduled)&.count || 0
  end

  shared_examples 'a failing service' do
    it 'raise an exception' do
      expect(ClusterInstallAppWorker).not_to receive(:perform_async)
      count_before = count_scheduled

      expect { service.execute }.to raise_error(StandardError)
      expect(count_scheduled).to eq(count_before)
    end
  end

  describe '#execute' do
    let(:application_class) { Clusters::Applications::Helm }
    let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
    let(:project) { cluster.project }
    let(:service) { described_class.new(project, nil, cluster: cluster, application_class: application_class) }

    it 'creates a new application' do
      allow(ClusterInstallAppWorker).to receive(:perform_async)

      expect { service.execute }.to change { application_class.count }.by(1)
    end

    it 'make the application scheduled' do
      expect(ClusterInstallAppWorker).to receive(:perform_async).with(application_class.application_name, kind_of(Numeric)).once

      expect { service.execute }.to change { application_class.with_status(:scheduled).count }.by(1)
    end

    context 'when installation is already in progress' do
      let(:application) { create(:clusters_applications_helm, :installing) }
      let(:cluster) { application.cluster }

      it_behaves_like 'a failing service'
    end

    context 'when application_class is nil' do
      let(:application_class) { nil }

      it_behaves_like 'a failing service'
    end

    context 'when application cannot be persisted' do
      before do
        expect_any_instance_of(application_class).to receive(:make_scheduled!).once.and_raise(ActiveRecord::RecordInvalid)
      end

      it_behaves_like 'a failing service'
    end
  end
end