diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-11 06:09:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-11 06:09:46 +0000 |
commit | 55733b19c526145cceb120e8bb874d476a84383a (patch) | |
tree | dcde3cfb905516cd1f07ab364a94aff5fddff391 /spec/services/ci | |
parent | ea99abb145ed193c2ac5d19efbff3b8990a54c9c (diff) | |
download | gitlab-ce-55733b19c526145cceb120e8bb874d476a84383a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/ci')
-rw-r--r-- | spec/services/ci/create_cross_project_pipeline_service_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb | 133 |
2 files changed, 134 insertions, 3 deletions
diff --git a/spec/services/ci/create_cross_project_pipeline_service_spec.rb b/spec/services/ci/create_cross_project_pipeline_service_spec.rb index f90cdb55a7a..8a1763b30ed 100644 --- a/spec/services/ci/create_cross_project_pipeline_service_spec.rb +++ b/spec/services/ci/create_cross_project_pipeline_service_spec.rb @@ -342,9 +342,7 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do let(:service) { described_class.new(upstream_project, upstream_project.owner) } context 'that include the bridge job' do - # TODO: this is skipped because `trigger` keyword does not exist yet. - # enabling it in the next MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24393 - xit 'creates the downstream pipeline' do + it 'creates the downstream pipeline' do expect { service.execute(bridge) } .to change(downstream_project.ci_pipelines, :count).by(1) end 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 new file mode 100644 index 00000000000..cfb68ffa585 --- /dev/null +++ b/spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb @@ -0,0 +1,133 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::CreatePipelineService, '#execute' do + set(:project) { create(:project, :repository) } + set(:user) { create(:user) } + let(:ref_name) { 'master' } + + let(:service) do + params = { ref: ref_name, + before: '00000000', + after: project.commit.id, + commits: [{ message: 'some commit' }] } + + described_class.new(project, user, params) + end + + before do + project.add_developer(user) + stub_ci_pipeline_to_return_yaml_file + 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 + + 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) + end + end + + describe 'child pipeline triggers' do + context 'when YAML is valid' 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 + + 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) + end + end + + context 'when YAML is invalid' do + let(:config) do + { + test: { script: 'rspec' }, + deploy: { + trigger: { include: included_files } + } + } + end + + let(:included_files) do + Array.new(include_max_size + 1) do |index| + { local: "file#{index}.yml" } + end + end + + let(:include_max_size) do + Gitlab::Ci::Config::Entry::Trigger::ComplexTrigger::SameProjectTrigger::INCLUDE_MAX_SIZE + end + + before do + stub_ci_pipeline_yaml_file(YAML.dump(config)) + end + + it 'returns errors' do + pipeline = create_pipeline! + + 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' + end + end + end + + def create_pipeline! + service.execute(:push) + end +end |