diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 03:09:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 03:09:07 +0300 |
commit | e144369009f3404072f7e0f969f7cded93195a01 (patch) | |
tree | d7a354e2c3c69a7ad65dc81aba8fe2ba59b0a26f /spec/services/ci | |
parent | d466ee5042520ad078fe050cb078d81dc2ebe196 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/ci')
-rw-r--r-- | spec/services/ci/stop_environments_service_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/services/ci/stop_environments_service_spec.rb b/spec/services/ci/stop_environments_service_spec.rb index ed92625a2cc..88f2f5618c2 100644 --- a/spec/services/ci/stop_environments_service_spec.rb +++ b/spec/services/ci/stop_environments_service_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe Ci::StopEnvironmentsService do + include CreateEnvironmentsHelpers + let(:project) { create(:project, :private, :repository) } let(:user) { create(:user) } @@ -181,6 +183,55 @@ describe Ci::StopEnvironmentsService do end end + describe '.execute_in_batch' do + subject { described_class.execute_in_batch(environments) } + + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let(:environments) { Environment.available } + + before_all do + project.add_developer(user) + project.repository.add_branch(user, 'review/feature-1', 'master') + project.repository.add_branch(user, 'review/feature-2', 'master') + end + + before do + create_review_app(user, project, 'review/feature-1') + create_review_app(user, project, 'review/feature-2') + end + + it 'stops environments' do + expect { subject } + .to change { project.environments.all.map(&:state).uniq } + .from(['available']).to(['stopped']) + + expect(project.environments.all.map(&:auto_stop_at).uniq).to eq([nil]) + end + + it 'plays stop actions' do + expect { subject } + .to change { Ci::Build.where(name: 'stop_review_app').map(&:status).uniq } + .from(['manual']).to(['pending']) + end + + context 'when user does not have a permission to play the stop action' do + before do + Ci::Build.find_by_ref('review/feature-2').update_column(:user_id, nil) + end + + it 'tracks the exception' do + deployable = Ci::Build.find_by_ref('review/feature-2') + + expect(Gitlab::ErrorTracking) + .to receive(:track_error) + .with(Gitlab::Access::AccessDeniedError, deployable_id: deployable.id).once + + subject + end + end + end + def expect_environment_stopped_on(branch) expect_any_instance_of(Environment) .to receive(:stop!) |