diff options
Diffstat (limited to 'spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb | 100 |
1 files changed, 87 insertions, 13 deletions
diff --git a/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb index 0c5d172f17c..af6ec25b9d6 100644 --- a/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb +++ b/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb @@ -20,16 +20,8 @@ describe 'Auto-DevOps.gitlab-ci.yml' do allow(project).to receive(:default_branch).and_return(default_branch) end - it 'creates a build and a test job' do - expect(build_names).to include('build', 'test') - end - - context 'when the project has no active cluster' do - it 'only creates a build and a test stage' do - expect(pipeline.stages_names).to eq(%w(build test)) - end - - it 'does not create any deployment-related builds' do + shared_examples 'no Kubernetes deployment job' do + it 'does not create any Kubernetes deployment-related builds' do expect(build_names).not_to include('production') expect(build_names).not_to include('production_manual') expect(build_names).not_to include('staging') @@ -39,13 +31,95 @@ describe 'Auto-DevOps.gitlab-ci.yml' do end end - context 'when the project has an active cluster' do - let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } + it 'creates a build and a test job' do + expect(build_names).to include('build', 'test') + end + + context 'when the project is set for deployment to AWS' do + let(:platform_value) { 'ECS' } before do - allow(cluster).to receive(:active?).and_return(true) + create(:ci_variable, project: project, key: 'AUTO_DEVOPS_PLATFORM_TARGET', value: platform_value) + end + + shared_examples 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do |job_name| + context 'when AUTO_DEVOPS_PLATFORM_TARGET is nil' do + let(:platform_value) { nil } + + it 'does not trigger the job' do + expect(build_names).not_to include(job_name) + end + end + + context 'when AUTO_DEVOPS_PLATFORM_TARGET is empty' do + let(:platform_value) { '' } + + it 'does not trigger the job' do + expect(build_names).not_to include(job_name) + end + end + end + + it_behaves_like 'no Kubernetes deployment job' + + it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do + let(:job_name) { 'production_ecs' } + end + + it 'creates an ECS deployment job for production only' do + expect(build_names).not_to include('review_ecs') + expect(build_names).to include('production_ecs') end + context 'and we are not on the default branch' do + let(:platform_value) { 'ECS' } + let(:pipeline_branch) { 'patch-1' } + + before do + project.repository.create_branch(pipeline_branch) + end + + it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do + let(:job_name) { 'review_ecs' } + end + + it 'creates an ECS deployment job for review only' do + expect(build_names).to include('review_ecs') + expect(build_names).not_to include('production_ecs') + expect(build_names).not_to include('review') + expect(build_names).not_to include('production') + end + end + + context 'and when the project has an active cluster' do + let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } + + before do + allow(cluster).to receive(:active?).and_return(true) + end + + context 'on default branch' do + it 'triggers the deployment to Kubernetes, not to ECS' do + expect(build_names).not_to include('review') + expect(build_names).to include('production') + expect(build_names).not_to include('production_ecs') + expect(build_names).not_to include('review_ecs') + end + end + end + end + + context 'when the project has no active cluster' do + it 'only creates a build and a test stage' do + expect(pipeline.stages_names).to eq(%w(build test)) + end + + it_behaves_like 'no Kubernetes deployment job' + end + + context 'when the project has an active cluster' do + let!(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } + describe 'deployment-related builds' do context 'on default branch' do it 'does not include rollout jobs besides production' do |