diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-01-25 12:31:49 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-01-25 12:31:49 +0000 |
commit | 5ab285490aec3f9400ec26123dc874a9b8327d4c (patch) | |
tree | c118d742844941b804001279eca9e070990b1482 /spec | |
parent | f438618115f6a47116f2b7396b82b8756c09631d (diff) | |
parent | 2d154cee32a01fd0880594d9635362df13bcdfb1 (diff) | |
download | gitlab-ce-5ab285490aec3f9400ec26123dc874a9b8327d4c.tar.gz |
Merge branch 'feature/gb/cross-project-pipeline-trigger' into 'master'
Cross-project pipeline triggers /CE
See merge request gitlab-org/gitlab-ce!24664
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/bridge.rb | 8 | ||||
-rw-r--r-- | spec/features/projects/pipelines/pipeline_spec.rb | 43 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/seed/build_spec.rb | 44 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 2 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 23 |
8 files changed, 132 insertions, 45 deletions
diff --git a/spec/factories/ci/bridge.rb b/spec/factories/ci/bridge.rb index 5f83b80ad7b..39427f416a0 100644 --- a/spec/factories/ci/bridge.rb +++ b/spec/factories/ci/bridge.rb @@ -10,8 +10,16 @@ FactoryBot.define do pipeline factory: :ci_pipeline + transient { downstream nil } + after(:build) do |bridge, evaluator| bridge.project ||= bridge.pipeline.project + + if evaluator.downstream.present? + bridge.options = bridge.options.to_h.merge( + trigger: { project: evaluator.downstream.full_path } + ) + end end end end diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb index 3192c9ffad4..72ef460d315 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -286,6 +286,49 @@ describe 'Pipeline', :js do end end + context 'when a bridge job exists' do + include_context 'pipeline builds' + + let(:project) { create(:project, :repository) } + let(:downstream) { create(:project, :repository) } + + let(:pipeline) do + create(:ci_pipeline, project: project, + ref: 'master', + sha: project.commit.id, + user: user) + end + + let!(:bridge) do + create(:ci_bridge, pipeline: pipeline, + name: 'cross-build', + user: user, + downstream: downstream) + end + + describe 'GET /:project/pipelines/:id' do + before do + visit project_pipeline_path(project, pipeline) + end + + it 'shows the pipeline with a bridge job' do + expect(page).to have_selector('.pipeline-visualization') + expect(page).to have_content('cross-build') + end + end + + describe 'GET /:project/pipelines/:id/builds' do + before do + visit builds_project_pipeline_path(project, pipeline) + end + + it 'shows a bridge job on a list' do + expect(page).to have_content('cross-build') + expect(page).to have_content(bridge.id) + end + end + end + describe 'GET /:project/pipelines/:id/builds' do include_context 'pipeline builds' diff --git a/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb index 3459939267a..0302e4090cf 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb @@ -163,14 +163,14 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ->(pipeline) { pipeline.variables.create!(key: 'VAR', value: '123') } end - it 'raises exception' do + it 'wastes pipeline iid' do expect { step.perform! }.to raise_error(ActiveRecord::RecordNotSaved) - end - it 'wastes pipeline iid' do - expect { step.perform! }.to raise_error + last_iid = InternalId.ci_pipelines + .where(project_id: project.id) + .last.last_value - expect(InternalId.ci_pipelines.where(project_id: project.id).last.last_value).to be > 0 + expect(last_iid).to be > 0 end end end diff --git a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb index a700cfd4546..fae8add6453 100644 --- a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb @@ -5,8 +5,7 @@ describe Gitlab::Ci::Pipeline::Seed::Build do let(:pipeline) { create(:ci_empty_pipeline, project: project) } let(:attributes) do - { name: 'rspec', - ref: 'master' } + { name: 'rspec', ref: 'master' } end subject do @@ -21,10 +20,45 @@ describe Gitlab::Ci::Pipeline::Seed::Build do end end + describe '#bridge?' do + context 'when job is a bridge' do + let(:attributes) do + { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } } + end + + it { is_expected.to be_bridge } + end + + context 'when trigger definition is empty' do + let(:attributes) do + { name: 'rspec', ref: 'master', options: { trigger: '' } } + end + + it { is_expected.not_to be_bridge } + end + + context 'when job is not a bridge' do + it { is_expected.not_to be_bridge } + end + end + describe '#to_resource' do - it 'returns a valid build resource' do - expect(subject.to_resource).to be_a(::Ci::Build) - expect(subject.to_resource).to be_valid + context 'when job is not a bridge' do + it 'returns a valid build resource' do + expect(subject.to_resource).to be_a(::Ci::Build) + expect(subject.to_resource).to be_valid + end + end + + context 'when job is a bridge' do + let(:attributes) do + { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } } + end + + it 'returns a valid bridge resource' do + expect(subject.to_resource).to be_a(::Ci::Bridge) + expect(subject.to_resource).to be_valid + end end it 'memoizes a resource object' do diff --git a/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb index 82f741845db..493ca3cd7b5 100644 --- a/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb @@ -62,8 +62,18 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do expect(subject.seeds.map(&:attributes)).to all(include(ref: 'master')) expect(subject.seeds.map(&:attributes)).to all(include(tag: false)) expect(subject.seeds.map(&:attributes)).to all(include(project: pipeline.project)) - expect(subject.seeds.map(&:attributes)) - .to all(include(trigger_request: pipeline.trigger_requests.first)) + end + + context 'when a legacy trigger exists' do + before do + create(:ci_trigger_request, pipeline: pipeline) + end + + it 'returns build seeds including legacy trigger' do + expect(pipeline.legacy_trigger).not_to be_nil + expect(subject.seeds.map(&:attributes)) + .to all(include(trigger_request: pipeline.legacy_trigger)) + end end context 'when a ref is protected' do diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 20c35573cfb..91139d421f5 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -21,15 +21,12 @@ module Gitlab stage: "test", stage_idx: 1, name: "rspec", - coverage_regex: nil, - tag_list: [], options: { before_script: ["pwd"], script: ["rspec"] }, allow_failure: false, when: "on_success", - environment: nil, yaml_variables: [] }) end @@ -154,12 +151,9 @@ module Gitlab builds: [{ stage_idx: 1, stage: "test", - tag_list: [], name: "rspec", allow_failure: false, when: "on_success", - environment: nil, - coverage_regex: nil, yaml_variables: [], options: { script: ["rspec"] }, only: { refs: ["branches"] }, @@ -169,12 +163,9 @@ module Gitlab builds: [{ stage_idx: 2, stage: "deploy", - tag_list: [], name: "prod", allow_failure: false, when: "on_success", - environment: nil, - coverage_regex: nil, yaml_variables: [], options: { script: ["cap prod"] }, only: { refs: ["tags"] }, @@ -344,8 +335,6 @@ module Gitlab stage: "test", stage_idx: 1, name: "rspec", - coverage_regex: nil, - tag_list: [], options: { before_script: ["pwd"], script: ["rspec"], @@ -356,7 +345,6 @@ module Gitlab }, allow_failure: false, when: "on_success", - environment: nil, yaml_variables: [] }) end @@ -378,8 +366,6 @@ module Gitlab stage: "test", stage_idx: 1, name: "rspec", - coverage_regex: nil, - tag_list: [], options: { before_script: ["pwd"], script: ["rspec"], @@ -390,7 +376,6 @@ module Gitlab }, allow_failure: false, when: "on_success", - environment: nil, yaml_variables: [] }) end @@ -410,8 +395,6 @@ module Gitlab stage: "test", stage_idx: 1, name: "rspec", - coverage_regex: nil, - tag_list: [], options: { before_script: ["pwd"], script: ["rspec"], @@ -420,7 +403,6 @@ module Gitlab }, allow_failure: false, when: "on_success", - environment: nil, yaml_variables: [] }) end @@ -438,8 +420,6 @@ module Gitlab stage: "test", stage_idx: 1, name: "rspec", - coverage_regex: nil, - tag_list: [], options: { before_script: ["pwd"], script: ["rspec"], @@ -448,7 +428,6 @@ module Gitlab }, allow_failure: false, when: "on_success", - environment: nil, yaml_variables: [] }) end @@ -763,8 +742,6 @@ module Gitlab stage: "test", stage_idx: 1, name: "rspec", - coverage_regex: nil, - tag_list: [], options: { before_script: ["pwd"], script: ["rspec"], @@ -779,7 +756,6 @@ module Gitlab }, when: "on_success", allow_failure: false, - environment: nil, yaml_variables: [] }) end @@ -976,14 +952,11 @@ module Gitlab stage: "test", stage_idx: 1, name: "normal_job", - coverage_regex: nil, - tag_list: [], options: { script: ["test"] }, when: "on_success", allow_failure: false, - environment: nil, yaml_variables: [] }) end @@ -1023,28 +996,22 @@ module Gitlab stage: "build", stage_idx: 0, name: "job1", - coverage_regex: nil, - tag_list: [], options: { script: ["execute-script-for-job"] }, when: "on_success", allow_failure: false, - environment: nil, yaml_variables: [] }) expect(subject.second).to eq({ stage: "build", stage_idx: 0, name: "job2", - coverage_regex: nil, - tag_list: [], options: { script: ["execute-script-for-job"] }, when: "on_success", allow_failure: false, - environment: nil, yaml_variables: [] }) end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 5afa9669b1a..6897ac8a3a8 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -114,6 +114,7 @@ ci_pipelines: - stages - statuses - builds +- processables - trigger_requests - variables - auto_canceled_by @@ -137,6 +138,7 @@ stages: - pipeline - statuses - builds +- bridges statuses: - project - pipeline diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 17f33785fda..72a0df96a80 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -39,6 +39,29 @@ describe Ci::Pipeline, :mailer do end end + describe '.processables' do + before do + create(:ci_build, name: 'build', pipeline: pipeline) + create(:ci_bridge, name: 'bridge', pipeline: pipeline) + create(:commit_status, name: 'commit status', pipeline: pipeline) + create(:generic_commit_status, name: 'generic status', pipeline: pipeline) + end + + it 'has an association with processable CI/CD entities' do + pipeline.processables.pluck('name').yield_self do |processables| + expect(processables).to match_array %w[build bridge] + end + end + + it 'makes it possible to append a new processable' do + pipeline.processables << build(:ci_bridge) + + pipeline.save! + + expect(pipeline.processables.reload.count).to eq 3 + end + end + describe '.sort_by_merge_request_pipelines' do subject { described_class.sort_by_merge_request_pipelines } |