diff options
Diffstat (limited to 'spec/lib/gitlab/ci/config')
14 files changed, 219 insertions, 221 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/bridge_spec.rb b/spec/lib/gitlab/ci/config/entry/bridge_spec.rb index 736c184a289..567ffa68836 100644 --- a/spec/lib/gitlab/ci/config/entry/bridge_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/bridge_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Bridge do # as they do not have sense in context of Bridge let(:ignored_inheritable_columns) do %i[before_script after_script hooks image services cache interruptible timeout - retry tags artifacts] + retry tags artifacts id_tokens] end end diff --git a/spec/lib/gitlab/ci/config/entry/default_spec.rb b/spec/lib/gitlab/ci/config/entry/default_spec.rb index 46e96843ee3..17e716629cd 100644 --- a/spec/lib/gitlab/ci/config/entry/default_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/default_spec.rb @@ -27,7 +27,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Default do it 'contains the expected node names' do expect(described_class.nodes.keys) .to match_array(%i[before_script after_script hooks cache image services - interruptible timeout retry tags artifacts]) + interruptible timeout retry tags artifacts id_tokens]) end end end diff --git a/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb b/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb index dd15b049b9b..cd8e35ede61 100644 --- a/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' # Change this to fast spec helper when FF `ci_refactor_external_rules` is removed +require 'fast_spec_helper' require_dependency 'active_model' RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules::Rule, feature_category: :pipeline_composition do @@ -14,21 +14,11 @@ RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules::Rule, feature_category entry.compose! end - shared_examples 'a valid config' do + shared_examples 'a valid config' do |expected_value = nil| it { is_expected.to be_valid } it 'returns the expected value' do - expect(entry.value).to eq(config.compact) - end - - context 'when FF `ci_refactor_external_rules` is disabled' do - before do - stub_feature_flags(ci_refactor_external_rules: false) - end - - it 'returns the expected value' do - expect(entry.value).to eq(config) - end + expect(entry.value).to eq(expected_value || config.compact) end end @@ -99,19 +89,37 @@ RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules::Rule, feature_category it_behaves_like 'a valid config' - context 'when array' do + context 'when exists: clause is an array' do let(:config) { { exists: ['./this.md', './that.md'] } } it_behaves_like 'a valid config' end - context 'when null' do + context 'when exists: clause is null' do let(:config) { { exists: nil } } it_behaves_like 'a valid config' end end + context 'when specifying a changes: clause' do + let(:config) { { changes: %w[Dockerfile lib/* paths/**/*.rb] } } + + it_behaves_like 'a valid config', { changes: { paths: %w[Dockerfile lib/* paths/**/*.rb] } } + + context 'with paths:' do + let(:config) { { changes: { paths: %w[Dockerfile lib/* paths/**/*.rb] } } } + + it_behaves_like 'a valid config' + end + + context 'with paths: and compare_to:' do + let(:config) { { changes: { paths: ['Dockerfile'], compare_to: 'branch1' } } } + + it_behaves_like 'a valid config' + end + end + context 'when specifying an unknown keyword' do let(:config) { { invalid: :something } } diff --git a/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb b/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb index 05db81abfc1..503020e2202 100644 --- a/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' # Change this to fast spec helper when FF `ci_refactor_external_rules` is removed +require 'fast_spec_helper' require_dependency 'active_model' RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules, feature_category: :pipeline_composition do @@ -50,7 +50,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules, feature_category: :pip entry.compose! end - it_behaves_like 'an invalid config', /contains unknown keys: changes/ + it_behaves_like 'a valid config' end end @@ -80,7 +80,8 @@ RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules, feature_category: :pip let(:config) do [ { if: '$THIS == "that"' }, - { if: '$SKIP', when: 'never' } + { if: '$SKIP', when: 'never' }, + { changes: ['Dockerfile'] } ] end @@ -96,7 +97,8 @@ RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules, feature_category: :pip is_expected.to eq( [ { if: '$THIS == "that"' }, - { if: '$SKIP', when: 'never' } + { if: '$SKIP', when: 'never' }, + { changes: { paths: ['Dockerfile'] } } ] ) end @@ -115,30 +117,5 @@ RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules, feature_category: :pip end end end - - context 'when FF `ci_refactor_external_rules` is disabled' do - before do - stub_feature_flags(ci_refactor_external_rules: false) - end - - context 'with an "if"' do - let(:config) do - [{ if: '$THIS == "that"' }] - end - - it { is_expected.to eq(config) } - end - - context 'with a list of two rules' do - let(:config) do - [ - { if: '$THIS == "that"' }, - { if: '$SKIP' } - ] - end - - it { is_expected.to eq(config) } - end - 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 4be7c11fab0..1a78d929871 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Gitlab::Ci::Config::Entry::Job, feature_category: :pipeline_composition do + using RSpec::Parameterized::TableSyntax + let(:entry) { described_class.new(config, name: :rspec) } it_behaves_like 'with inheritable CI config' do @@ -29,7 +31,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job, feature_category: :pipeline_compo let(:result) do %i[before_script script after_script hooks stage cache image services only except rules needs variables artifacts - environment coverage retry interruptible timeout release tags + coverage retry interruptible timeout release tags inherit parallel] end @@ -696,8 +698,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job, feature_category: :pipeline_compo end context 'with workflow rules' do - using RSpec::Parameterized::TableSyntax - where(:name, :has_workflow_rules?, :only, :rules, :result) do "uses default only" | false | nil | nil | { refs: %w[branches tags] } "uses user only" | false | %w[branches] | nil | { refs: %w[branches] } @@ -739,6 +739,20 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job, feature_category: :pipeline_compo end end + describe '#pages_job?', :aggregate_failures, feature_category: :pages do + where(:name, :result) do + :pages | true + :'pages:staging' | false + :'something:pages:else' | false + end + + with_them do + subject { described_class.new({}, name: name).pages_job? } + + it { is_expected.to eq(result) } + end + end + context 'when composed' do before do entry.compose! diff --git a/spec/lib/gitlab/ci/config/entry/processable_spec.rb b/spec/lib/gitlab/ci/config/entry/processable_spec.rb index 4f13940d7e2..132e75a808b 100644 --- a/spec/lib/gitlab/ci/config/entry/processable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/processable_spec.rb @@ -371,6 +371,39 @@ RSpec.describe Gitlab::Ci::Config::Entry::Processable, feature_category: :pipeli end end + context 'with environment' do + context 'when environment name is specified' do + let(:config) { { script: 'ls', environment: 'prod' }.compact } + + it 'sets environment name and action to the entry value' do + entry.compose!(deps) + + expect(entry.value[:environment]).to eq({ action: 'start', name: 'prod' }) + expect(entry.value[:environment_name]).to eq('prod') + end + end + + context 'when environment name, url and action are specified' do + let(:config) do + { + script: 'ls', + environment: { + name: 'staging', + url: 'https://gitlab.com', + action: 'prepare' + } + }.compact + end + + it 'sets environment name, action and url to the entry value' do + entry.compose!(deps) + + expect(entry.value[:environment]).to eq({ action: 'prepare', name: 'staging', url: 'https://gitlab.com' }) + expect(entry.value[:environment_name]).to eq('staging') + end + end + end + context 'with inheritance' do context 'of default:tags' do using RSpec::Parameterized::TableSyntax diff --git a/spec/lib/gitlab/ci/config/external/context_spec.rb b/spec/lib/gitlab/ci/config/external/context_spec.rb index d8bd578be94..9ac72ebbac8 100644 --- a/spec/lib/gitlab/ci/config/external/context_spec.rb +++ b/spec/lib/gitlab/ci/config/external/context_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Gitlab::Ci::Config::External::Context, feature_category: :pipeline_composition do let(:project) { build(:project) } + let(:pipeline) { double('Pipeline') } let(:user) { double('User') } let(:sha) { '12345' } let(:variables) { Gitlab::Ci::Variables::Collection.new([{ 'key' => 'a', 'value' => 'b' }]) } @@ -11,6 +12,7 @@ RSpec.describe Gitlab::Ci::Config::External::Context, feature_category: :pipelin let(:attributes) do { project: project, + pipeline: pipeline, user: user, sha: sha, variables: variables, @@ -32,7 +34,7 @@ RSpec.describe Gitlab::Ci::Config::External::Context, feature_category: :pipelin end context 'without values' do - let(:attributes) { { project: nil, user: nil, sha: nil } } + let(:attributes) { { project: nil, pipeline: nil, user: nil, sha: nil } } it { is_expected.to have_attributes(**attributes) } it { expect(subject.expandset).to eq([]) } @@ -148,6 +150,7 @@ RSpec.describe Gitlab::Ci::Config::External::Context, feature_category: :pipelin let(:attributes) do { project: project, + pipeline: pipeline, user: user, sha: sha, logger: double('logger') @@ -165,6 +168,7 @@ RSpec.describe Gitlab::Ci::Config::External::Context, feature_category: :pipelin it { expect(mutated).not_to eq(subject) } it { expect(mutated).to be_a(described_class) } it { expect(mutated).to have_attributes(new_attributes) } + it { expect(mutated.pipeline).to eq(subject.pipeline) } it { expect(mutated.expandset).to eq(subject.expandset) } it { expect(mutated.execution_deadline).to eq(mutated.execution_deadline) } it { expect(mutated.logger).to eq(mutated.logger) } diff --git a/spec/lib/gitlab/ci/config/external/file/component_spec.rb b/spec/lib/gitlab/ci/config/external/file/component_spec.rb index 487690296b5..0f7b811b5df 100644 --- a/spec/lib/gitlab/ci/config/external/file/component_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/component_spec.rb @@ -120,6 +120,41 @@ RSpec.describe Gitlab::Ci::Config::External::File::Component, feature_category: end end + describe '#content' do + context 'when component is valid' do + let(:content) do + <<~COMPONENT + job: + script: echo + COMPONENT + end + + let(:response) do + ServiceResponse.success(payload: { + content: content, + path: instance_double(::Gitlab::Ci::Components::InstancePath, project: project, sha: '12345') + }) + end + + it 'tracks the event' do + expect(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with('cicd_component_usage', + values: external_resource.context.user.id) + + external_resource.content + end + end + + context 'when component is invalid' do + let(:content) { 'the-content' } + + it 'does not track the event' do + expect(::Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event) + + external_resource.content + end + end + end + describe '#metadata' do subject(:metadata) { external_resource.metadata } diff --git a/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb index 69b0524be9e..f542c0485e0 100644 --- a/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb +++ b/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb @@ -409,32 +409,6 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper::Verifier, feature_category: expect { process }.to raise_error(expected_error_class) end end - - context 'when introduce_ci_max_total_yaml_size_bytes is disabled' do - before do - stub_feature_flags(introduce_ci_max_total_yaml_size_bytes: false) - end - - context 'when pipeline tree size is within the limit' do - before do - stub_application_setting(ci_max_total_yaml_size_bytes: 10000) - end - - it 'passes the verification' do - expect(process.all?(&:valid?)).to be_truthy - end - end - - context 'when pipeline tree size is larger then the limit' do - before do - stub_application_setting(ci_max_total_yaml_size_bytes: 100) - end - - it 'passes the verification' do - expect(process.all?(&:valid?)).to be_truthy - end - end - end end end end diff --git a/spec/lib/gitlab/ci/config/external/processor_spec.rb b/spec/lib/gitlab/ci/config/external/processor_spec.rb index 19113ce6a4e..68cdf56f198 100644 --- a/spec/lib/gitlab/ci/config/external/processor_spec.rb +++ b/spec/lib/gitlab/ci/config/external/processor_spec.rb @@ -557,21 +557,11 @@ RSpec.describe Gitlab::Ci::Config::External::Processor, feature_category: :pipel context 'when rules defined' do context 'when a rule is invalid' do let(:values) do - { include: [{ local: 'builds.yml', rules: [{ changes: ['$MY_VAR'] }] }] } + { include: [{ local: 'builds.yml', rules: [{ allow_failure: ['$MY_VAR'] }] }] } end it 'raises IncludeError' do - expect { subject }.to raise_error(described_class::IncludeError, /contains unknown keys: changes/) - end - - context 'when FF `ci_refactor_external_rules` is disabled' do - before do - stub_feature_flags(ci_refactor_external_rules: false) - end - - it 'raises IncludeError' do - expect { subject }.to raise_error(described_class::IncludeError, /invalid include rule/) - end + expect { subject }.to raise_error(described_class::IncludeError, /contains unknown keys: allow_failure/) end end end diff --git a/spec/lib/gitlab/ci/config/external/rules_spec.rb b/spec/lib/gitlab/ci/config/external/rules_spec.rb index 8674af7ab65..15d7801ff2a 100644 --- a/spec/lib/gitlab/ci/config/external/rules_spec.rb +++ b/spec/lib/gitlab/ci/config/external/rules_spec.rb @@ -4,76 +4,45 @@ require 'spec_helper' RSpec.describe Gitlab::Ci::Config::External::Rules, feature_category: :pipeline_composition do let(:context) { double(variables_hash: {}) } - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"' }] } + let(:rule_hashes) {} + let(:pipeline) { instance_double(Ci::Pipeline) } + let_it_be(:project) { create(:project, :custom_repo, files: { 'file.txt' => 'file' }) } subject(:rules) { described_class.new(rule_hashes) } + before do + allow(context).to receive(:project).and_return(project) + allow(context).to receive(:pipeline).and_return(pipeline) + end + describe '#evaluate' do subject(:result) { rules.evaluate(context).pass? } context 'when there is no rule' do - let(:rule_hashes) {} - it { is_expected.to eq(true) } end - shared_examples 'when there is a rule with if' do |rule_matched_result = true, rule_not_matched_result = false| - context 'when the rule matches' do - let(:context) { double(variables_hash: { 'MY_VAR' => 'hello' }) } - - it { is_expected.to eq(rule_matched_result) } - end - - context 'when the rule does not match' do - let(:context) { double(variables_hash: { 'MY_VAR' => 'invalid' }) } - - it { is_expected.to eq(rule_not_matched_result) } - end - end - - shared_examples 'when there is a rule with exists' do |file_exists_result = true, file_not_exists_result = false| - let(:project) { create(:project, :repository) } - - context 'when the file exists' do - let(:context) { double(project: project, sha: project.repository.tree.sha, top_level_worktree_paths: ['Dockerfile']) } - + shared_examples 'with when: specified' do + context 'with when: never' do before do - project.repository.create_file(project.first_owner, 'Dockerfile', "commit", message: 'test', branch_name: "master") + rule_hashes.first[:when] = 'never' end - it { is_expected.to eq(file_exists_result) } - end - - context 'when the file does not exist' do - let(:context) { double(project: project, sha: project.repository.tree.sha, top_level_worktree_paths: ['test.md']) } - - it { is_expected.to eq(file_not_exists_result) } - end - end - - it_behaves_like 'when there is a rule with if' - - context 'when there is a rule with exists' do - let(:rule_hashes) { [{ exists: 'Dockerfile' }] } - - it_behaves_like 'when there is a rule with exists' - end - - context 'when there is a rule with if and when' do - context 'with when: never' do - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'never' }] } - - it_behaves_like 'when there is a rule with if', false, false + it { is_expected.to eq(false) } end context 'with when: always' do - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'always' }] } + before do + rule_hashes.first[:when] = 'always' + end - it_behaves_like 'when there is a rule with if' + it { is_expected.to eq(true) } end context 'with when: <invalid string>' do - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'on_success' }] } + before do + rule_hashes.first[:when] = 'on_success' + end it 'raises an error' do expect { result }.to raise_error(described_class::InvalidIncludeRulesError, /when unknown value: on_success/) @@ -81,132 +50,125 @@ RSpec.describe Gitlab::Ci::Config::External::Rules, feature_category: :pipeline_ end context 'with when: null' do - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: nil }] } + before do + rule_hashes.first[:when] = nil + end - it_behaves_like 'when there is a rule with if' + it { is_expected.to eq(true) } end end - context 'when there is a rule with exists and when' do - context 'with when: never' do - let(:rule_hashes) { [{ exists: 'Dockerfile', when: 'never' }] } + context 'when there is a rule with if:' do + let(:rule_hashes) { [{ if: '$MY_VAR == "hello"' }] } - it_behaves_like 'when there is a rule with exists', false, false - end + context 'when the rule matches' do + let(:context) { double(variables_hash: { 'MY_VAR' => 'hello' }) } - context 'with when: always' do - let(:rule_hashes) { [{ exists: 'Dockerfile', when: 'always' }] } + it { is_expected.to eq(true) } - it_behaves_like 'when there is a rule with exists' + it_behaves_like 'with when: specified' end - context 'with when: <invalid string>' do - let(:rule_hashes) { [{ exists: 'Dockerfile', when: 'on_success' }] } + context 'when the rule does not match' do + let(:context) { double(variables_hash: { 'MY_VAR' => 'invalid' }) } - it 'raises an error' do - expect { result }.to raise_error(described_class::InvalidIncludeRulesError, /when unknown value: on_success/) - end + it { is_expected.to eq(false) } end + end - context 'with when: null' do - let(:rule_hashes) { [{ exists: 'Dockerfile', when: nil }] } + context 'when there is a rule with exists:' do + let(:rule_hashes) { [{ exists: 'file.txt' }] } - it_behaves_like 'when there is a rule with exists' + context 'when the file exists' do + let(:context) { double(top_level_worktree_paths: ['file.txt']) } + + it { is_expected.to eq(true) } + + it_behaves_like 'with when: specified' end - end - context 'when there is a rule with changes' do - let(:rule_hashes) { [{ changes: ['$MY_VAR'] }] } + context 'when the file does not exist' do + let(:context) { double(top_level_worktree_paths: ['README.md']) } - it 'raises an error' do - expect { result }.to raise_error(described_class::InvalidIncludeRulesError, /contains unknown keys: changes/) + it { is_expected.to eq(false) } end end - context 'when FF `ci_refactor_external_rules` is disabled' do - before do - stub_feature_flags(ci_refactor_external_rules: false) - end + context 'when there is a rule with changes:' do + let(:rule_hashes) { [{ changes: ['file.txt'] }] } - context 'when there is no rule' do - let(:rule_hashes) {} + shared_examples 'when the pipeline has modified paths' do + let(:modified_paths) { ['file.txt'] } - it { is_expected.to eq(true) } - end + before do + allow(pipeline).to receive(:modified_paths).and_return(modified_paths) + end - it_behaves_like 'when there is a rule with if' + context 'when the file has changed' do + it { is_expected.to eq(true) } - context 'when there is a rule with exists' do - let(:rule_hashes) { [{ exists: 'Dockerfile' }] } + it_behaves_like 'with when: specified' + end - it_behaves_like 'when there is a rule with exists' + context 'when the file has not changed' do + let(:modified_paths) { ['README.md'] } + + it { is_expected.to eq(false) } + end end - context 'when there is a rule with if and when' do - context 'with when: never' do - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'never' }] } + it_behaves_like 'when the pipeline has modified paths' - it_behaves_like 'when there is a rule with if', false, false - end + context 'with paths: specified' do + let(:rule_hashes) { [{ changes: { paths: ['file.txt'] } }] } - context 'with when: always' do - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'always' }] } + it_behaves_like 'when the pipeline has modified paths' + end - it_behaves_like 'when there is a rule with if' - end + context 'with paths: and compare_to: specified' do + before_all do + project.repository.add_branch(project.owner, 'branch1', 'master') - context 'with when: <invalid string>' do - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'on_success' }] } + project.repository.update_file( + project.owner, 'file.txt', 'file updated', message: 'Update file.txt', branch_name: 'branch1' + ) - it 'raises an error' do - expect { result }.to raise_error(described_class::InvalidIncludeRulesError, - 'invalid include rule: {:if=>"$MY_VAR == \"hello\"", :when=>"on_success"}') - end + project.repository.add_branch(project.owner, 'branch2', 'branch1') end - context 'with when: null' do - let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: nil }] } - - it_behaves_like 'when there is a rule with if' + let_it_be(:pipeline) do + build(:ci_pipeline, project: project, ref: 'branch2', sha: project.commit('branch2').sha) end - end - context 'when there is a rule with exists and when' do - context 'with when: never' do - let(:rule_hashes) { [{ exists: 'Dockerfile', when: 'never' }] } + context 'when the file has changed compared to the given ref' do + let(:rule_hashes) { [{ changes: { paths: ['file.txt'], compare_to: 'master' } }] } + + it { is_expected.to eq(true) } - it_behaves_like 'when there is a rule with exists', false, false + it_behaves_like 'with when: specified' end - context 'with when: always' do - let(:rule_hashes) { [{ exists: 'Dockerfile', when: 'always' }] } + context 'when the file has not changed compared to the given ref' do + let(:rule_hashes) { [{ changes: { paths: ['file.txt'], compare_to: 'branch1' } }] } - it_behaves_like 'when there is a rule with exists' + it { is_expected.to eq(false) } end - context 'with when: <invalid string>' do - let(:rule_hashes) { [{ exists: 'Dockerfile', when: 'on_success' }] } + context 'when compare_to: is invalid' do + let(:rule_hashes) { [{ changes: { paths: ['file.txt'], compare_to: 'invalid' } }] } it 'raises an error' do - expect { result }.to raise_error(described_class::InvalidIncludeRulesError, - 'invalid include rule: {:exists=>"Dockerfile", :when=>"on_success"}') + expect { result }.to raise_error(described_class::InvalidIncludeRulesError, /compare_to is not a valid ref/) end end - - context 'with when: null' do - let(:rule_hashes) { [{ exists: 'Dockerfile', when: nil }] } - - it_behaves_like 'when there is a rule with exists' - end end + end - context 'when there is a rule with changes' do - let(:rule_hashes) { [{ changes: ['$MY_VAR'] }] } + context 'when there is a rule with an invalid key' do + let(:rule_hashes) { [{ invalid: ['$MY_VAR'] }] } - it 'raises an error' do - expect { result }.to raise_error(described_class::InvalidIncludeRulesError, - 'invalid include rule: {:changes=>["$MY_VAR"]}') - end + it 'raises an error' do + expect { result }.to raise_error(described_class::InvalidIncludeRulesError, /contains unknown keys: invalid/) end end end diff --git a/spec/lib/gitlab/ci/config/interpolation/interpolator_spec.rb b/spec/lib/gitlab/ci/config/interpolation/interpolator_spec.rb index 7bb09d35064..804164c933a 100644 --- a/spec/lib/gitlab/ci/config/interpolation/interpolator_spec.rb +++ b/spec/lib/gitlab/ci/config/interpolation/interpolator_spec.rb @@ -57,7 +57,8 @@ RSpec.describe Gitlab::Ci::Config::Interpolation::Interpolator, feature_category expect(subject).not_to be_valid expect(subject.error_message).to eq subject.errors.first - expect(subject.errors).to include('unknown input arguments') + expect(subject.errors).to include('Given inputs not defined in the `spec` section of the included ' \ + 'configuration file') end end diff --git a/spec/lib/gitlab/ci/config/yaml/tags/reference_spec.rb b/spec/lib/gitlab/ci/config/yaml/tags/reference_spec.rb index bf89942bf14..0af1b721eb6 100644 --- a/spec/lib/gitlab/ci/config/yaml/tags/reference_spec.rb +++ b/spec/lib/gitlab/ci/config/yaml/tags/reference_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Config::Yaml::Tags::Reference do +RSpec.describe Gitlab::Ci::Config::Yaml::Tags::Reference, feature_category: :pipeline_composition do let(:config) do - Gitlab::Ci::Config::Yaml.load!(yaml) + Gitlab::Ci::Config::Yaml::Loader.new(yaml).load.content end describe '.tag' do diff --git a/spec/lib/gitlab/ci/config/yaml/tags/resolver_spec.rb b/spec/lib/gitlab/ci/config/yaml/tags/resolver_spec.rb index 594242c33cc..74d7513ebdf 100644 --- a/spec/lib/gitlab/ci/config/yaml/tags/resolver_spec.rb +++ b/spec/lib/gitlab/ci/config/yaml/tags/resolver_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Config::Yaml::Tags::Resolver do +RSpec.describe Gitlab::Ci::Config::Yaml::Tags::Resolver, feature_category: :pipeline_composition do let(:config) do - Gitlab::Ci::Config::Yaml.load!(yaml) + Gitlab::Ci::Config::Yaml::Loader.new(yaml).load.content end describe '#to_hash' do |