diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 09:09:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 09:09:05 +0300 |
commit | 8c9dc985b90c353b33cb829caf51f8320171bc15 (patch) | |
tree | 9a68886dbea1aefabddb46bbd3faf961eab22ae6 /spec/lib/gitlab | |
parent | 500626a5c953ad81cfc3ed74bf0148c075617e58 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/ci/build/rules_spec.rb | 50 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/bridge_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/job_spec.rb | 7 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/jobs_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/root_spec.rb | 15 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb | 45 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/seed/build_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 53 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/safe_model_attributes.yml | 1 |
10 files changed, 158 insertions, 37 deletions
diff --git a/spec/lib/gitlab/ci/build/rules_spec.rb b/spec/lib/gitlab/ci/build/rules_spec.rb index 1ebcc4f9414..31a9fa055e1 100644 --- a/spec/lib/gitlab/ci/build/rules_spec.rb +++ b/spec/lib/gitlab/ci/build/rules_spec.rb @@ -102,9 +102,9 @@ describe Gitlab::Ci::Build::Rules do end context 'with one rule without any clauses' do - let(:rule_list) { [{ when: 'manual' }] } + let(:rule_list) { [{ when: 'manual', allow_failure: true }] } - it { is_expected.to eq(described_class::Result.new('manual')) } + it { is_expected.to eq(described_class::Result.new('manual', nil, true)) } end context 'with one matching rule' do @@ -166,5 +166,51 @@ describe Gitlab::Ci::Build::Rules do end end end + + context 'with only allow_failure' do + context 'with matching rule' do + let(:rule_list) { [{ if: '$VAR == null', allow_failure: true }] } + + it { is_expected.to eq(described_class::Result.new('on_success', nil, true)) } + end + + context 'with non-matching rule' do + let(:rule_list) { [{ if: '$VAR != null', allow_failure: true }] } + + it { is_expected.to eq(described_class::Result.new('never')) } + end + end + end + + describe 'Gitlab::Ci::Build::Rules::Result' do + let(:when_value) { 'on_success' } + let(:start_in) { nil } + let(:allow_failure) { nil } + + subject { Gitlab::Ci::Build::Rules::Result.new(when_value, start_in, allow_failure) } + + describe '#build_attributes' do + it 'compacts nil values' do + expect(subject.build_attributes).to eq(options: {}, when: 'on_success') + end + end + + describe '#pass?' do + context "'when' is 'never'" do + let!(:when_value) { 'never' } + + it 'returns false' do + expect(subject.pass?).to eq(false) + end + end + + context "'when' is 'on_success'" do + let!(:when_value) { 'on_success' } + + it 'returns true' do + expect(subject.pass?).to eq(true) + end + end + end end end diff --git a/spec/lib/gitlab/ci/config/entry/bridge_spec.rb b/spec/lib/gitlab/ci/config/entry/bridge_spec.rb index 07590556db8..ad388886681 100644 --- a/spec/lib/gitlab/ci/config/entry/bridge_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/bridge_spec.rb @@ -105,7 +105,8 @@ describe Gitlab::Ci::Config::Entry::Bridge do trigger: { project: 'some/project' }, ignore: false, stage: 'test', - only: { refs: %w[branches tags] }) + only: { refs: %w[branches tags] }, + scheduling_type: :stage) end end end @@ -126,7 +127,8 @@ describe Gitlab::Ci::Config::Entry::Bridge do branch: 'feature' }, ignore: false, stage: 'test', - only: { refs: %w[branches tags] }) + only: { refs: %w[branches tags] }, + scheduling_type: :stage) end end end diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index 649689f7d3b..313b504ab59 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -110,6 +110,10 @@ describe Gitlab::Ci::Config::Entry::Job do it { expect(entry).to be_valid } + it "returns scheduling_type as :dag" do + expect(entry.value[:scheduling_type]).to eq(:dag) + end + context 'when has dependencies' do let(:config) do { @@ -598,7 +602,8 @@ describe Gitlab::Ci::Config::Entry::Job do ignore: false, after_script: %w[cleanup], only: { refs: %w[branches tags] }, - variables: {}) + variables: {}, + scheduling_type: :stage) end end end diff --git a/spec/lib/gitlab/ci/config/entry/jobs_spec.rb b/spec/lib/gitlab/ci/config/entry/jobs_spec.rb index 05249b7c717..c8c188d71bf 100644 --- a/spec/lib/gitlab/ci/config/entry/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/jobs_spec.rb @@ -98,7 +98,8 @@ describe Gitlab::Ci::Config::Entry::Jobs do name: :my_trigger, only: { refs: %w[branches tags] }, stage: 'test', - trigger: { project: 'my/project' } + trigger: { project: 'my/project' }, + scheduling_type: :stage }, regular_job: { ignore: false, @@ -106,7 +107,8 @@ describe Gitlab::Ci::Config::Entry::Jobs do only: { refs: %w[branches tags] }, script: ['something'], stage: 'test', - variables: {} + variables: {}, + scheduling_type: :stage }) end end diff --git a/spec/lib/gitlab/ci/config/entry/root_spec.rb b/spec/lib/gitlab/ci/config/entry/root_spec.rb index 95a5b8e88fb..cf0a3cfa963 100644 --- a/spec/lib/gitlab/ci/config/entry/root_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/root_spec.rb @@ -130,7 +130,8 @@ describe Gitlab::Ci::Config::Entry::Root do variables: {}, ignore: false, after_script: ['make clean'], - only: { refs: %w[branches tags] } } + only: { refs: %w[branches tags] }, + scheduling_type: :stage } ) expect(root.jobs_value[:spinach]).to eq( { name: :spinach, @@ -143,7 +144,8 @@ describe Gitlab::Ci::Config::Entry::Root do variables: {}, ignore: false, after_script: ['make clean'], - only: { refs: %w[branches tags] } } + only: { refs: %w[branches tags] }, + scheduling_type: :stage } ) expect(root.jobs_value[:release]).to eq( { name: :release, @@ -157,7 +159,8 @@ describe Gitlab::Ci::Config::Entry::Root do only: { refs: %w(branches tags) }, variables: {}, after_script: [], - ignore: false } + ignore: false, + scheduling_type: :stage } ) end end @@ -203,7 +206,8 @@ describe Gitlab::Ci::Config::Entry::Root do variables: {}, ignore: false, after_script: ['make clean'], - only: { refs: %w[branches tags] } }, + only: { refs: %w[branches tags] }, + scheduling_type: :stage }, spinach: { name: :spinach, before_script: [], script: %w[spinach], @@ -214,7 +218,8 @@ describe Gitlab::Ci::Config::Entry::Root do variables: { 'VAR' => 'AA' }, ignore: false, after_script: ['make clean'], - only: { refs: %w[branches tags] } } + only: { refs: %w[branches tags] }, + scheduling_type: :stage } ) end end diff --git a/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb b/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb index 216f5d0c77d..20db5f02fc7 100644 --- a/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb @@ -27,8 +27,14 @@ describe Gitlab::Ci::Config::Entry::Rules::Rule do it { is_expected.to be_valid } end + context 'with an allow_failure: value but no clauses' do + let(:config) { { allow_failure: true } } + + it { is_expected.to be_valid } + end + context 'when specifying an if: clause' do - let(:config) { { if: '$THIS || $THAT', when: 'manual' } } + let(:config) { { if: '$THIS || $THAT', when: 'manual', allow_failure: true } } it { is_expected.to be_valid } @@ -37,6 +43,12 @@ describe Gitlab::Ci::Config::Entry::Rules::Rule do it { is_expected.to eq('manual') } end + + describe '#allow_failure' do + subject { entry.allow_failure } + + it { is_expected.to eq(true) } + end end context 'using a list of multiple expressions' do @@ -328,16 +340,43 @@ describe Gitlab::Ci::Config::Entry::Rules::Rule do end end end + + context 'allow_failure: validation' do + context 'with an invalid string allow_failure:' do + let(:config) do + { if: '$THIS == "that"', allow_failure: 'always' } + end + + it { is_expected.to be_a(described_class) } + it { is_expected.not_to be_valid } + + it 'returns an error about invalid allow_failure:' do + expect(subject.errors).to include(/rule allow failure should be a boolean value/) + end + + context 'when composed' do + before do + subject.compose! + end + + it { is_expected.not_to be_valid } + + it 'returns an error about invalid allow_failure:' do + expect(subject.errors).to include(/rule allow failure should be a boolean value/) + end + end + end + end end describe '#value' do subject { entry.value } context 'when specifying an if: clause' do - let(:config) { { if: '$THIS || $THAT', when: 'manual' } } + let(:config) { { if: '$THIS || $THAT', when: 'manual', allow_failure: true } } it 'stores the expression as "if"' do - expect(subject).to eq(if: '$THIS || $THAT', when: 'manual') + expect(subject).to eq(if: '$THIS || $THAT', when: 'manual', allow_failure: true) 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 5526ec9e16f..1f5fc000832 100644 --- a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::Ci::Pipeline::Seed::Build do let(:project) { create(:project, :repository) } let(:head_sha) { project.repository.head_commit.id } let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: head_sha) } - let(:attributes) { { name: 'rspec', ref: 'master' } } + let(:attributes) { { name: 'rspec', ref: 'master', scheduling_type: :stage } } let(:previous_stages) { [] } let(:seed_build) { described_class.new(pipeline, attributes, previous_stages) } @@ -244,7 +244,9 @@ describe Gitlab::Ci::Pipeline::Seed::Build do context 'when job is a bridge' do let(:attributes) do - { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } } + { + name: 'rspec', ref: 'master', options: { trigger: 'my/project' }, scheduling_type: :stage + } end it { is_expected.to be_a(::Ci::Bridge) } diff --git a/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb index a978084876f..875fd457bd0 100644 --- a/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb @@ -10,9 +10,9 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do let(:attributes) do { name: 'test', index: 0, - builds: [{ name: 'rspec' }, - { name: 'spinach' }, - { name: 'deploy', only: { refs: ['feature'] } }] } + builds: [{ name: 'rspec', scheduling_type: :stage }, + { name: 'spinach', scheduling_type: :stage }, + { name: 'deploy', only: { refs: ['feature'] } }], scheduling_type: :stage } end subject do diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 11168a969fc..e5c5aaa2265 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -36,7 +36,8 @@ module Gitlab interruptible: true, allow_failure: false, when: "on_success", - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end end @@ -66,7 +67,8 @@ module Gitlab ], allow_failure: false, when: 'on_success', - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end end @@ -126,7 +128,8 @@ module Gitlab interruptible: true, allow_failure: false, when: "on_success", - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end end @@ -282,6 +285,7 @@ module Gitlab allow_failure: false, when: "on_success", yaml_variables: [], + scheduling_type: :stage, options: { script: ["rspec"] }, only: { refs: ["branches"] } }] }, { name: "deploy", @@ -293,6 +297,7 @@ module Gitlab allow_failure: false, when: "on_success", yaml_variables: [], + scheduling_type: :stage, options: { script: ["cap prod"] }, only: { refs: ["tags"] } }] }, { name: ".post", @@ -642,7 +647,8 @@ module Gitlab }, allow_failure: false, when: "on_success", - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end @@ -674,7 +680,8 @@ module Gitlab }, allow_failure: false, when: "on_success", - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end end @@ -702,7 +709,8 @@ module Gitlab }, allow_failure: false, when: "on_success", - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end @@ -728,7 +736,8 @@ module Gitlab }, allow_failure: false, when: "on_success", - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end end @@ -1250,7 +1259,8 @@ module Gitlab }, when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end @@ -1604,7 +1614,8 @@ module Gitlab }, when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage ) expect(subject.builds[4]).to eq( stage: "test", @@ -1618,7 +1629,8 @@ module Gitlab ], when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :dag ) end end @@ -1644,7 +1656,8 @@ module Gitlab }, when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage ) expect(subject.builds[4]).to eq( stage: "test", @@ -1660,7 +1673,8 @@ module Gitlab ], when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :dag ) end end @@ -1682,7 +1696,8 @@ module Gitlab ], when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :dag ) end end @@ -1712,7 +1727,8 @@ module Gitlab ], when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :dag ) end end @@ -1849,7 +1865,8 @@ module Gitlab }, when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end end @@ -1895,7 +1912,8 @@ module Gitlab }, when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) expect(subject.second).to eq({ stage: "build", @@ -1907,7 +1925,8 @@ module Gitlab }, when: "on_success", allow_failure: false, - yaml_variables: [] + yaml_variables: [], + scheduling_type: :stage }) end end diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index 55e7d6bd1e3..807b017a67c 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -360,6 +360,7 @@ CommitStatus: - upstream_pipeline_id - interruptible - processed +- scheduling_type Ci::Variable: - id - project_id |