summaryrefslogtreecommitdiff
path: root/spec/services/ci
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 15:09:29 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 15:09:29 +0000
commit209bd8cf1f542f6ba2a069b368a9187faa871e96 (patch)
tree6b77dc8183135b8316cc70c8dbc9c4e7c18cf05a /spec/services/ci
parenta9ced7da447785c57477b3d8dbccc73a78cface1 (diff)
downloadgitlab-ce-209bd8cf1f542f6ba2a069b368a9187faa871e96.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/ci')
-rw-r--r--spec/services/ci/create_pipeline_service/parent_child_pipeline_spec.rb200
-rw-r--r--spec/services/ci/pipeline_processing/shared_processing_service.rb77
2 files changed, 153 insertions, 124 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
diff --git a/spec/services/ci/pipeline_processing/shared_processing_service.rb b/spec/services/ci/pipeline_processing/shared_processing_service.rb
index ca003299535..ffe5eacfc48 100644
--- a/spec/services/ci/pipeline_processing/shared_processing_service.rb
+++ b/spec/services/ci/pipeline_processing/shared_processing_service.rb
@@ -757,73 +757,19 @@ shared_examples 'Pipeline Processing Service' do
expect(builds.pending).to contain_exactly(deploy)
end
- context 'when feature ci_dag_support is disabled' do
- before do
- stub_feature_flags(ci_dag_support: false)
- end
-
- it 'when linux:build finishes first it follows stages' do
- expect(process_pipeline).to be_truthy
-
- expect(stages).to eq(%w(pending created created))
- expect(builds.pending).to contain_exactly(linux_build, mac_build)
-
- # we follow the single path of linux
- linux_build.reset.success!
-
- expect(stages).to eq(%w(running created created))
- expect(builds.success).to contain_exactly(linux_build)
- expect(builds.pending).to contain_exactly(mac_build)
-
- mac_build.reset.success!
-
- expect(stages).to eq(%w(success pending created))
- expect(builds.success).to contain_exactly(linux_build, mac_build)
- expect(builds.pending).to contain_exactly(
- linux_rspec, linux_rubocop, mac_rspec, mac_rubocop)
-
- linux_rspec.reset.success!
- linux_rubocop.reset.success!
- mac_rspec.reset.success!
- mac_rubocop.reset.success!
-
- expect(stages).to eq(%w(success success pending))
- expect(builds.success).to contain_exactly(
- linux_build, linux_rspec, linux_rubocop, mac_build, mac_rspec, mac_rubocop)
- expect(builds.pending).to contain_exactly(deploy)
- end
- end
-
context 'when one of the jobs is run on a failure' do
let!(:linux_notify) { create_build('linux:notify', stage: 'deploy', stage_idx: 2, when: 'on_failure', scheduling_type: :dag) }
let!(:linux_notify_on_build) { create(:ci_build_need, build: linux_notify, name: 'linux:build') }
context 'when another job in build phase fails first' do
- context 'when ci_dag_support is enabled' do
- it 'does skip linux:notify' do
- expect(process_pipeline).to be_truthy
-
- mac_build.reset.drop!
- linux_build.reset.success!
-
- expect(linux_notify.reset).to be_skipped
- end
- end
-
- context 'when ci_dag_support is disabled' do
- before do
- stub_feature_flags(ci_dag_support: false)
- end
-
- it 'does run linux:notify' do
- expect(process_pipeline).to be_truthy
+ it 'does skip linux:notify' do
+ expect(process_pipeline).to be_truthy
- mac_build.reset.drop!
- linux_build.reset.success!
+ mac_build.reset.drop!
+ linux_build.reset.success!
- expect(linux_notify.reset).to be_pending
- end
+ expect(linux_notify.reset).to be_skipped
end
end
@@ -864,19 +810,6 @@ shared_examples 'Pipeline Processing Service' do
expect(stages).to eq(%w(success success running))
expect(builds.pending).to contain_exactly(deploy)
end
-
- context 'when ci_dag_support is disabled' do
- before do
- stub_feature_flags(ci_dag_support: false)
- end
-
- it 'does run deploy_pages at the start' do
- expect(process_pipeline).to be_truthy
-
- expect(stages).to eq(%w(pending created created))
- expect(builds.pending).to contain_exactly(linux_build, mac_build)
- end
- end
end
end