diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-11 21:09:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-11 21:09:23 +0300 |
commit | 9d195600e6266da44917f08c622a21a6d4c2317b (patch) | |
tree | 4693fc9ee5e1ee1dc8fc39414f59976da188573b /spec/services/deployments | |
parent | 9c0f4306f6779e40acc3943d7050b706633da93e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/deployments')
-rw-r--r-- | spec/services/deployments/update_environment_service_spec.rb | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/spec/services/deployments/update_environment_service_spec.rb b/spec/services/deployments/update_environment_service_spec.rb index 92488c62315..ae5e8445554 100644 --- a/spec/services/deployments/update_environment_service_spec.rb +++ b/spec/services/deployments/update_environment_service_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Deployments::UpdateEnvironmentService do let(:user) { create(:user) } let(:project) { create(:project, :repository) } - let(:options) { { name: 'production' } } + let(:options) { { name: environment_name } } let(:pipeline) do create( :ci_pipeline, @@ -20,13 +20,14 @@ RSpec.describe Deployments::UpdateEnvironmentService do pipeline: pipeline, ref: 'master', tag: false, - environment: 'production', + environment: environment_name, options: { environment: options }, project: project) end let(:deployment) { job.deployment } let(:environment) { deployment.environment } + let(:environment_name) { 'production' } subject(:service) { described_class.new(deployment) } @@ -131,6 +132,66 @@ RSpec.describe Deployments::UpdateEnvironmentService do end end end + + context 'when deployment tier is specified' do + let(:environment_name) { 'customer-portal' } + let(:options) { { name: environment_name, deployment_tier: 'production' } } + + context 'when tier has already been set' do + before do + environment.update_column(:tier, Environment.tiers[:other]) + end + + it 'overwrites the guessed tier by the specified deployment tier' do + expect { subject.execute } + .to change { environment.reset.tier }.from('other').to('production') + end + end + + context 'when tier has not been set' do + before do + environment.update_column(:tier, nil) + end + + it 'sets the specified deployment tier' do + expect { subject.execute } + .to change { environment.reset.tier }.from(nil).to('production') + end + + context 'when deployment was created by an external CD system' do + before do + deployment.update_column(:deployable_id, nil) + end + + it 'guesses the deployment tier' do + expect { subject.execute } + .to change { environment.reset.tier }.from(nil).to('other') + end + end + + context 'when environment_tier feature flag is disabled' do + before do + stub_feature_flags(environment_tier: false) + end + + it 'does not set the specified deployment tier' do + expect { subject.execute }.not_to change { environment.reset.tier } + end + end + end + end + + context 'when deployment tier is not specified' do + let(:environment_name) { 'customer-portal' } + let(:options) { { name: environment_name } } + + it 'guesses the deployment tier' do + environment.update_column(:tier, nil) + + expect { subject.execute } + .to change { environment.reset.tier }.from(nil).to('other') + end + end end describe '#expanded_environment_url' do |