diff options
Diffstat (limited to 'spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb')
-rw-r--r-- | spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb | 200 |
1 files changed, 148 insertions, 52 deletions
diff --git a/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb b/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb index b4071d1b0fe..a76e83f2d60 100644 --- a/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb +++ b/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb @@ -18,25 +18,10 @@ describe Ci::CreatePipelineService, '#execute' do before do project.add_developer(user) - stub_ci_pipeline_to_return_yaml_file + stub_ci_pipeline_yaml_file(config) end - describe 'child pipeline triggers' do - before do - stub_ci_pipeline_yaml_file <<~YAML - test: - script: rspec - - deploy: - variables: - CROSS: downstream - stage: deploy - trigger: - include: - - local: path/to/child.yml - YAML - end - + shared_examples 'successful creation' do it 'creates bridge jobs correctly' do pipeline = create_pipeline! @@ -48,58 +33,140 @@ describe Ci::CreatePipelineService, '#execute' do expect(bridge).to be_a Ci::Bridge expect(bridge.stage).to eq 'deploy' expect(pipeline.statuses).to match_array [test, bridge] - expect(bridge.options).to eq( - 'trigger' => { 'include' => [{ 'local' => 'path/to/child.yml' }] } - ) + expect(bridge.options).to eq(expected_bridge_options) expect(bridge.yaml_variables) .to include(key: 'CROSS', value: 'downstream', public: true) end end + shared_examples 'creation failure' do + it 'returns errors' do + pipeline = create_pipeline! + + expect(pipeline.errors.full_messages.first).to match(expected_error) + expect(pipeline.failure_reason).to eq 'config_error' + expect(pipeline).to be_persisted + expect(pipeline.status).to eq 'failed' + end + end + + describe 'child pipeline triggers' do + let(:config) do + <<~YAML + test: + script: rspec + deploy: + variables: + CROSS: downstream + stage: deploy + trigger: + include: + - local: path/to/child.yml + YAML + end + + it_behaves_like 'successful creation' do + let(:expected_bridge_options) do + { + 'trigger' => { + 'include' => [ + { 'local' => 'path/to/child.yml' } + ] + } + } + end + end + end + describe 'child pipeline triggers' do context 'when YAML is valid' do - before do - stub_ci_pipeline_yaml_file <<~YAML + let(:config) do + <<~YAML + test: + script: rspec + deploy: + variables: + CROSS: downstream + stage: deploy + trigger: + include: + - local: path/to/child.yml + YAML + end + + it_behaves_like 'successful creation' do + let(:expected_bridge_options) do + { + 'trigger' => { + 'include' => [ + { 'local' => 'path/to/child.yml' } + ] + } + } + end + end + + context 'when trigger:include is specified as a string' do + let(:config) do + <<~YAML test: script: rspec + deploy: + variables: + CROSS: downstream + stage: deploy + trigger: + include: path/to/child.yml + YAML + end + + it_behaves_like 'successful creation' do + let(:expected_bridge_options) do + { + 'trigger' => { + 'include' => 'path/to/child.yml' + } + } + end + end + end + context 'when trigger:include is specified as array of strings' do + let(:config) do + <<~YAML + test: + script: rspec deploy: variables: CROSS: downstream stage: deploy trigger: include: - - local: path/to/child.yml - YAML - end + - path/to/child.yml + - path/to/child2.yml + YAML + end - it 'creates bridge jobs correctly' do - pipeline = create_pipeline! - - test = pipeline.statuses.find_by(name: 'test') - bridge = pipeline.statuses.find_by(name: 'deploy') - - expect(pipeline).to be_persisted - expect(test).to be_a Ci::Build - expect(bridge).to be_a Ci::Bridge - expect(bridge.stage).to eq 'deploy' - expect(pipeline.statuses).to match_array [test, bridge] - expect(bridge.options).to eq( - 'trigger' => { 'include' => [{ 'local' => 'path/to/child.yml' }] } - ) - expect(bridge.yaml_variables) - .to include(key: 'CROSS', value: 'downstream', public: true) + it_behaves_like 'successful creation' do + let(:expected_bridge_options) do + { + 'trigger' => { + 'include' => ['path/to/child.yml', 'path/to/child2.yml'] + } + } + end + end end end - context 'when YAML is invalid' do + context 'when limit of includes is reached' do let(:config) do - { + YAML.dump({ test: { script: 'rspec' }, deploy: { trigger: { include: included_files } } - } + }) end let(:included_files) do @@ -112,17 +179,46 @@ describe Ci::CreatePipelineService, '#execute' do Gitlab::Ci::Config::Entry::Trigger::ComplexTrigger::SameProjectTrigger::INCLUDE_MAX_SIZE end - before do - stub_ci_pipeline_yaml_file(YAML.dump(config)) + it_behaves_like 'creation failure' do + let(:expected_error) { /trigger:include config is too long/ } end + end - it 'returns errors' do - pipeline = create_pipeline! + context 'when including configs from artifact' do + context 'when specified dependency is in the wrong order' do + let(:config) do + <<~YAML + test: + trigger: + include: + - job: generator + artifact: 'generated.yml' + generator: + stage: 'deploy' + script: 'generator' + YAML + end - expect(pipeline.errors.full_messages.first).to match(/trigger:include config is too long/) - expect(pipeline.failure_reason).to eq 'config_error' - expect(pipeline).to be_persisted - expect(pipeline.status).to eq 'failed' + it_behaves_like 'creation failure' do + let(:expected_error) { /test job: dependency generator is not defined in prior stages/ } + end + end + + context 'when specified dependency is missing :job key' do + let(:config) do + <<~YAML + test: + trigger: + include: + - artifact: 'generated.yml' + YAML + end + + it_behaves_like 'creation failure' do + let(:expected_error) do + /include config must specify the job where to fetch the artifact from/ + end + end end end end |