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

stop_job_success_worker_spec.rb « environments « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3a2db8cfb77931d57b41754b843cf64d729bc125 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Environments::StopJobSuccessWorker, feature_category: :continuous_delivery do
  describe '#perform' do
    subject { described_class.new.perform(build.id) }

    context 'when build exists' do
      context 'when the build will stop an environment' do
        let!(:build) { create(:ci_build, :stop_review_app, environment: environment.name, project: environment.project, status: :success) } # rubocop:disable Layout/LineLength
        let(:environment) { create(:environment, state: :available) }

        it 'stops the environment' do
          expect(environment).to be_available

          subject

          expect(environment.reload).to be_stopped
        end

        context 'when the build fails' do
          before do
            build.update!(status: :failed)
            environment.update!(state: :available)
          end

          it 'does not stop the environment' do
            expect(environment).to be_available

            subject

            expect(environment.reload).not_to be_stopped
          end
        end
      end
    end

    context 'when build does not exist' do
      it 'does not raise exception' do
        expect { described_class.new.perform(123) }
          .not_to raise_error
      end
    end
  end
end