diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/services/ci/create_pipeline_service/include_spec.rb | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/services/ci/create_pipeline_service/include_spec.rb')
-rw-r--r-- | spec/services/ci/create_pipeline_service/include_spec.rb | 89 |
1 files changed, 73 insertions, 16 deletions
diff --git a/spec/services/ci/create_pipeline_service/include_spec.rb b/spec/services/ci/create_pipeline_service/include_spec.rb index 5e7dace8e15..aa01977272a 100644 --- a/spec/services/ci/create_pipeline_service/include_spec.rb +++ b/spec/services/ci/create_pipeline_service/include_spec.rb @@ -7,9 +7,11 @@ RSpec.describe Ci::CreatePipelineService do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { project.owner } - let(:ref) { 'refs/heads/master' } - let(:source) { :push } - let(:service) { described_class.new(project, user, { ref: ref }) } + let(:ref) { 'refs/heads/master' } + let(:variables_attributes) { [{ key: 'MYVAR', secret_value: 'hello' }] } + let(:source) { :push } + + let(:service) { described_class.new(project, user, { ref: ref, variables_attributes: variables_attributes }) } let(:pipeline) { service.execute(source).payload } let(:file_location) { 'spec/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml' } @@ -24,6 +26,20 @@ RSpec.describe Ci::CreatePipelineService do .and_return(File.read(Rails.root.join(file_location))) end + shared_examples 'not including the file' do + it 'does not include the job in the file' do + expect(pipeline).to be_created_successfully + expect(pipeline.processables.pluck(:name)).to contain_exactly('job') + end + end + + shared_examples 'including the file' do + it 'includes the job in the file' do + expect(pipeline).to be_created_successfully + expect(pipeline.processables.pluck(:name)).to contain_exactly('job', 'rspec') + end + end + context 'with a local file' do let(:config) do <<~EOY @@ -33,13 +49,10 @@ RSpec.describe Ci::CreatePipelineService do EOY end - it 'includes the job in the file' do - expect(pipeline).to be_created_successfully - expect(pipeline.processables.pluck(:name)).to contain_exactly('job', 'rspec') - end + it_behaves_like 'including the file' end - context 'with a local file with rules' do + context 'with a local file with rules with a project variable' do let(:config) do <<~EOY include: @@ -54,19 +67,63 @@ RSpec.describe Ci::CreatePipelineService do context 'when the rules matches' do let(:project_id) { project.id } - it 'includes the job in the file' do - expect(pipeline).to be_created_successfully - expect(pipeline.processables.pluck(:name)).to contain_exactly('job', 'rspec') - end + it_behaves_like 'including the file' end context 'when the rules does not match' do let(:project_id) { non_existing_record_id } - it 'does not include the job in the file' do - expect(pipeline).to be_created_successfully - expect(pipeline.processables.pluck(:name)).to contain_exactly('job') - end + it_behaves_like 'not including the file' + end + end + + context 'with a local file with rules with a predefined pipeline variable' do + let(:config) do + <<~EOY + include: + - local: #{file_location} + rules: + - if: $CI_PIPELINE_SOURCE == "#{pipeline_source}" + job: + script: exit 0 + EOY + end + + context 'when the rules matches' do + let(:pipeline_source) { 'push' } + + it_behaves_like 'including the file' + end + + context 'when the rules does not match' do + let(:pipeline_source) { 'web' } + + it_behaves_like 'not including the file' + end + end + + context 'with a local file with rules with a run pipeline variable' do + let(:config) do + <<~EOY + include: + - local: #{file_location} + rules: + - if: $MYVAR == "#{my_var}" + job: + script: exit 0 + EOY + end + + context 'when the rules matches' do + let(:my_var) { 'hello' } + + it_behaves_like 'including the file' + end + + context 'when the rules does not match' do + let(:my_var) { 'mello' } + + it_behaves_like 'not including the file' end end end |