diff options
Diffstat (limited to 'spec/lib/gitlab/ci/config')
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/cache_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/job_spec.rb | 186 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/processable_spec.rb | 143 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/product/matrix_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/product/parallel_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/reports_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/root_spec.rb | 15 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/variable_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/external/file/local_spec.rb | 31 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/external/mapper_spec.rb | 11 |
11 files changed, 226 insertions, 218 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/cache_spec.rb b/spec/lib/gitlab/ci/config/entry/cache_spec.rb index 414cbb169b9..67252eed938 100644 --- a/spec/lib/gitlab/ci/config/entry/cache_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/cache_spec.rb @@ -16,12 +16,14 @@ RSpec.describe Gitlab::Ci::Config::Entry::Cache do let(:policy) { nil } let(:key) { 'some key' } let(:when_config) { nil } + let(:unprotect) { false } let(:config) do { key: key, untracked: true, - paths: ['some/path/'] + paths: ['some/path/'], + unprotect: unprotect }.tap do |config| config[:policy] = policy if policy config[:when] = when_config if when_config @@ -31,7 +33,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Cache do describe '#value' do shared_examples 'hash key value' do it 'returns hash value' do - expect(entry.value).to eq(key: key, untracked: true, paths: ['some/path/'], policy: 'pull-push', when: 'on_success') + expect(entry.value).to eq(key: key, untracked: true, paths: ['some/path/'], policy: 'pull-push', when: 'on_success', unprotect: false) end end @@ -57,6 +59,14 @@ RSpec.describe Gitlab::Ci::Config::Entry::Cache do end end + context 'with option `unprotect` specified' do + let(:unprotect) { true } + + it 'returns true' do + expect(entry.value).to match(a_hash_including(unprotect: true)) + end + end + context 'with `policy`' do where(:policy, :result) do 'pull-push' | 'pull-push' diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index becb46ac2e7..c1b9bd58d98 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Config::Entry::Job do +RSpec.describe Gitlab::Ci::Config::Entry::Job, feature_category: :pipeline_authoring do let(:entry) { described_class.new(config, name: :rspec) } it_behaves_like 'with inheritable CI config' do @@ -337,100 +337,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do end end - context 'when only: is used with rules:' do - let(:config) { { only: ['merge_requests'], rules: [{ if: '$THIS' }] } } - - it 'returns error about mixing only: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end - - context 'and only: is blank' do - let(:config) { { only: nil, rules: [{ if: '$THIS' }] } } - - it 'returns error about mixing only: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end - end - - context 'and rules: is blank' do - let(:config) { { only: ['merge_requests'], rules: nil } } - - it 'returns error about mixing only: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end - end - end - - context 'when except: is used with rules:' do - let(:config) { { except: { refs: %w[master] }, rules: [{ if: '$THIS' }] } } - - it 'returns error about mixing except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end - - context 'and except: is blank' do - let(:config) { { except: nil, rules: [{ if: '$THIS' }] } } - - it 'returns error about mixing except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end - end - - context 'and rules: is blank' do - let(:config) { { except: { refs: %w[master] }, rules: nil } } - - it 'returns error about mixing except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end - end - end - - context 'when only: and except: are both used with rules:' do - let(:config) do - { - only: %w[merge_requests], - except: { refs: %w[master] }, - rules: [{ if: '$THIS' }] - } - end - - it 'returns errors about mixing both only: and except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - expect(entry.errors).to include /may not be used with `rules`/ - end - - context 'when only: and except: as both blank' do - let(:config) do - { only: nil, except: nil, rules: [{ if: '$THIS' }] } - end - - it 'returns errors about mixing both only: and except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - expect(entry.errors).to include /may not be used with `rules`/ - end - end - - context 'when rules: is blank' do - let(:config) do - { only: %w[merge_requests], except: { refs: %w[master] }, rules: nil } - end - - it 'returns errors about mixing both only: and except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - expect(entry.errors).to include /may not be used with `rules`/ - end - end - end - context 'when start_in specified without delayed specification' do let(:config) { { start_in: '1 day' } } @@ -603,6 +509,92 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do end end end + + context 'when only: is used with rules:' do + let(:config) { { only: ['merge_requests'], rules: [{ if: '$THIS' }], script: 'echo' } } + + it 'returns error about mixing only: with rules:' do + expect(entry).not_to be_valid + expect(entry.errors).to include /may not be used with `rules`: only/ + end + + context 'and only: is blank' do + let(:config) { { only: nil, rules: [{ if: '$THIS' }], script: 'echo' } } + + it 'is valid:' do + expect(entry).to be_valid + end + end + + context 'and rules: is blank' do + let(:config) { { only: ['merge_requests'], rules: nil, script: 'echo' } } + + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when except: is used with rules:' do + let(:config) { { except: { refs: %w[master] }, rules: [{ if: '$THIS' }], script: 'echo' } } + + it 'returns error about mixing except: with rules:' do + expect(entry).not_to be_valid + expect(entry.errors).to include /may not be used with `rules`: except/ + end + + context 'and except: is blank' do + let(:config) { { except: nil, rules: [{ if: '$THIS' }], script: 'echo' } } + + it 'is valid' do + expect(entry).to be_valid + end + end + + context 'and rules: is blank' do + let(:config) { { except: { refs: %w[master] }, rules: nil, script: 'echo' } } + + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when only: and except: are both used with rules:' do + let(:config) do + { + only: %w[merge_requests], + except: { refs: %w[master] }, + rules: [{ if: '$THIS' }], + script: 'echo' + } + end + + it 'returns errors about mixing both only: and except: with rules:' do + expect(entry).not_to be_valid + expect(entry.errors).to include /may not be used with `rules`: only, except/ + end + + context 'when only: and except: as both blank' do + let(:config) do + { only: nil, except: nil, rules: [{ if: '$THIS' }], script: 'echo' } + end + + it 'is valid' do + expect(entry).to be_valid + end + end + + context 'when rules: is blank' do + let(:config) do + { only: %w[merge_requests], except: { refs: %w[master] }, rules: nil, script: 'echo' } + end + + it 'is valid' do + expect(entry).to be_valid + end + end + end end describe '#relevant?' do @@ -639,7 +631,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do it 'overrides default config' do expect(entry[:image].value).to eq(name: 'some_image') - expect(entry[:cache].value).to eq([key: 'test', policy: 'pull-push', when: 'on_success']) + expect(entry[:cache].value).to eq([key: 'test', policy: 'pull-push', when: 'on_success', unprotect: false]) end end @@ -654,7 +646,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do it 'uses config from default entry' do expect(entry[:image].value).to eq 'specified' - expect(entry[:cache].value).to eq([key: 'test', policy: 'pull-push', when: 'on_success']) + expect(entry[:cache].value).to eq([key: 'test', policy: 'pull-push', when: 'on_success', unprotect: false]) end end diff --git a/spec/lib/gitlab/ci/config/entry/processable_spec.rb b/spec/lib/gitlab/ci/config/entry/processable_spec.rb index f1578a068b9..b28562ba2ea 100644 --- a/spec/lib/gitlab/ci/config/entry/processable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/processable_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Config::Entry::Processable do +RSpec.describe Gitlab::Ci::Config::Entry::Processable, feature_category: :pipeline_authoring do let(:node_class) do Class.new(::Gitlab::Config::Entry::Node) do include Gitlab::Ci::Config::Entry::Processable @@ -104,111 +104,102 @@ RSpec.describe Gitlab::Ci::Config::Entry::Processable do end end - context 'when only: is used with rules:' do - let(:config) { { only: ['merge_requests'], rules: [{ if: '$THIS' }] } } + context 'when a variable has an invalid data attribute' do + let(:config) do + { + script: 'echo', + variables: { 'VAR1' => 'val 1', 'VAR2' => { value: 'val 2', description: 'hello var 2' } } + } + end - it 'returns error about mixing only: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ + it 'reports error about variable' do + expect(entry.errors) + .to include 'variables:var2 config uses invalid data keys: description' end + end + end - context 'and only: is blank' do - let(:config) { { only: nil, rules: [{ if: '$THIS' }] } } + context 'when only: is used with rules:' do + let(:config) { { only: ['merge_requests'], rules: [{ if: '$THIS' }] } } - it 'returns error about mixing only: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end - end + it 'returns error about mixing only: with rules:' do + expect(entry).not_to be_valid + expect(entry.errors).to include /may not be used with `rules`: only/ + end - context 'and rules: is blank' do - let(:config) { { only: ['merge_requests'], rules: nil } } + context 'and only: is blank' do + let(:config) { { only: nil, rules: [{ if: '$THIS' }] } } - it 'returns error about mixing only: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end + it 'is valid' do + expect(entry).to be_valid end end - context 'when except: is used with rules:' do - let(:config) { { except: { refs: %w[master] }, rules: [{ if: '$THIS' }] } } + context 'and rules: is blank' do + let(:config) { { only: ['merge_requests'], rules: nil } } - it 'returns error about mixing except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ + it 'is valid' do + expect(entry).to be_valid end + end + end - context 'and except: is blank' do - let(:config) { { except: nil, rules: [{ if: '$THIS' }] } } + context 'when except: is used with rules:' do + let(:config) { { except: { refs: %w[master] }, rules: [{ if: '$THIS' }] } } - it 'returns error about mixing except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end - end + it 'returns error about mixing except: with rules:' do + expect(entry).not_to be_valid + expect(entry.errors).to include /may not be used with `rules`: except/ + end - context 'and rules: is blank' do - let(:config) { { except: { refs: %w[master] }, rules: nil } } + context 'and except: is blank' do + let(:config) { { except: nil, rules: [{ if: '$THIS' }] } } - it 'returns error about mixing except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - end + it 'is valid' do + expect(entry).to be_valid end end - context 'when only: and except: are both used with rules:' do - let(:config) do - { - only: %w[merge_requests], - except: { refs: %w[master] }, - rules: [{ if: '$THIS' }] - } - end + context 'and rules: is blank' do + let(:config) { { except: { refs: %w[master] }, rules: nil } } - it 'returns errors about mixing both only: and except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - expect(entry.errors).to include /may not be used with `rules`/ + it 'is valid' do + expect(entry).to be_valid end + end + end - context 'when only: and except: as both blank' do - let(:config) do - { only: nil, except: nil, rules: [{ if: '$THIS' }] } - end + context 'when only: and except: are both used with rules:' do + let(:config) do + { + only: %w[merge_requests], + except: { refs: %w[master] }, + rules: [{ if: '$THIS' }] + } + end - it 'returns errors about mixing both only: and except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - expect(entry.errors).to include /may not be used with `rules`/ - end - end + it 'returns errors about mixing both only: and except: with rules:' do + expect(entry).not_to be_valid + expect(entry.errors).to include /may not be used with `rules`: only, except/ + end - context 'when rules: is blank' do - let(:config) do - { only: %w[merge_requests], except: { refs: %w[master] }, rules: nil } - end + context 'when only: and except: as both blank' do + let(:config) do + { only: nil, except: nil, rules: [{ if: '$THIS' }] } + end - it 'returns errors about mixing both only: and except: with rules:' do - expect(entry).not_to be_valid - expect(entry.errors).to include /may not be used with `rules`/ - expect(entry.errors).to include /may not be used with `rules`/ - end + it 'is valid' do + expect(entry).to be_valid end end - context 'when a variable has an invalid data attribute' do + context 'when rules: is blank' do let(:config) do - { - script: 'echo', - variables: { 'VAR1' => 'val 1', 'VAR2' => { value: 'val 2', description: 'hello var 2' } } - } + { only: %w[merge_requests], except: { refs: %w[master] }, rules: nil } end - it 'reports error about variable' do - expect(entry.errors) - .to include 'variables:var2 config uses invalid data keys: description' + it 'is valid' do + expect(entry).to be_valid end end end diff --git a/spec/lib/gitlab/ci/config/entry/product/matrix_spec.rb b/spec/lib/gitlab/ci/config/entry/product/matrix_spec.rb index 394d91466bf..cbd3109522c 100644 --- a/spec/lib/gitlab/ci/config/entry/product/matrix_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/product/matrix_spec.rb @@ -29,7 +29,7 @@ RSpec.describe ::Gitlab::Ci::Config::Entry::Product::Matrix do [ { 'VAR_1' => (1..10).to_a, - 'VAR_2' => (11..20).to_a + 'VAR_2' => (11..31).to_a } ] end @@ -41,7 +41,7 @@ RSpec.describe ::Gitlab::Ci::Config::Entry::Product::Matrix do describe '#errors' do it 'returns error about too many jobs' do expect(matrix.errors) - .to include('matrix config generates too many jobs (maximum is 50)') + .to include('matrix config generates too many jobs (maximum is 200)') end end end diff --git a/spec/lib/gitlab/ci/config/entry/product/parallel_spec.rb b/spec/lib/gitlab/ci/config/entry/product/parallel_spec.rb index a16f1cf9e43..ec21519a8f6 100644 --- a/spec/lib/gitlab/ci/config/entry/product/parallel_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/product/parallel_spec.rb @@ -33,10 +33,10 @@ RSpec.describe ::Gitlab::Ci::Config::Entry::Product::Parallel do it_behaves_like 'invalid config', /must be greater than or equal to 2/ end - context 'when it is bigger than 50' do - let(:config) { 51 } + context 'when it is bigger than 200' do + let(:config) { 201 } - it_behaves_like 'invalid config', /must be less than or equal to 50/ + it_behaves_like 'invalid config', /must be less than or equal to 200/ end context 'when it is not an integer' do diff --git a/spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb b/spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb index 0fd9a83a4fa..ccd6f6ab427 100644 --- a/spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/reports/coverage_report_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Config::Entry::Reports::CoverageReport do +RSpec.describe Gitlab::Ci::Config::Entry::Reports::CoverageReport, feature_category: :pipeline_authoring do let(:entry) { described_class.new(config) } describe 'validations' do @@ -14,6 +14,16 @@ RSpec.describe Gitlab::Ci::Config::Entry::Reports::CoverageReport do it { expect(entry.value).to eq(config) } end + context 'when it is not a hash' do + where(:config) { ['string', true, []] } + + with_them do + it { expect(entry).not_to be_valid } + + it { expect(entry.errors).to include /should be a hash/ } + end + end + context 'with unsupported coverage format' do let(:config) { { coverage_format: 'jacoco', path: 'jacoco.xml' } } diff --git a/spec/lib/gitlab/ci/config/entry/reports_spec.rb b/spec/lib/gitlab/ci/config/entry/reports_spec.rb index 45aa859a356..715cb18fb92 100644 --- a/spec/lib/gitlab/ci/config/entry/reports_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/reports_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Config::Entry::Reports do +RSpec.describe Gitlab::Ci::Config::Entry::Reports, feature_category: :pipeline_authoring do let(:entry) { described_class.new(config) } describe 'validates ALLOWED_KEYS' do @@ -90,6 +90,18 @@ RSpec.describe Gitlab::Ci::Config::Entry::Reports do end end end + + context 'when coverage_report is nil' do + let(:config) { { coverage_report: nil } } + + it 'is valid' do + expect(entry).to be_valid + end + + it 'returns artifacts configuration as an empty hash' do + expect(entry.value).to eq({}) + end + end end context 'when entry value is not correct' do diff --git a/spec/lib/gitlab/ci/config/entry/root_spec.rb b/spec/lib/gitlab/ci/config/entry/root_spec.rb index c40589104cd..9722609aef6 100644 --- a/spec/lib/gitlab/ci/config/entry/root_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/root_spec.rb @@ -127,7 +127,8 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do image: { name: 'image:1.0' }, services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }], stage: 'test', - cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' }], + cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success', + unprotect: false }], job_variables: {}, root_variables_inheritance: true, ignore: false, @@ -142,7 +143,8 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do image: { name: 'image:1.0' }, services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }], stage: 'test', - cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' }], + cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success', + unprotect: false }], job_variables: {}, root_variables_inheritance: true, ignore: false, @@ -158,7 +160,8 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do release: { name: "Release $CI_TAG_NAME", tag_name: 'v0.06', description: "./release_changelog.txt" }, image: { name: "image:1.0" }, services: [{ name: "postgres:9.1" }, { name: "mysql:5.5" }], - cache: [{ key: "k", untracked: true, paths: ["public/"], policy: "pull-push", when: 'on_success' }], + cache: [{ key: "k", untracked: true, paths: ["public/"], policy: "pull-push", when: 'on_success', + unprotect: false }], only: { refs: %w(branches tags) }, job_variables: { 'VAR' => { value: 'job' } }, root_variables_inheritance: true, @@ -206,7 +209,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do image: { name: 'image:1.0' }, services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }], stage: 'test', - cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' }], + cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success', unprotect: false }], job_variables: {}, root_variables_inheritance: true, ignore: false, @@ -219,7 +222,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do image: { name: 'image:1.0' }, services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }], stage: 'test', - cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' }], + cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success', unprotect: false }], job_variables: { 'VAR' => { value: 'job' } }, root_variables_inheritance: true, ignore: false, @@ -274,7 +277,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do describe '#cache_value' do it 'returns correct cache definition' do - expect(root.cache_value).to eq([key: 'a', policy: 'pull-push', when: 'on_success']) + expect(root.cache_value).to eq([key: 'a', policy: 'pull-push', when: 'on_success', unprotect: false]) end end end diff --git a/spec/lib/gitlab/ci/config/entry/variable_spec.rb b/spec/lib/gitlab/ci/config/entry/variable_spec.rb index 97b06c8b1a5..1067db6d124 100644 --- a/spec/lib/gitlab/ci/config/entry/variable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/variable_spec.rb @@ -257,14 +257,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Variable do subject(:value_with_data) { entry.value_with_data } it { is_expected.to eq(value: 'value', raw: true) } - - context 'when the FF ci_raw_variables_in_yaml_config is disabled' do - before do - stub_feature_flags(ci_raw_variables_in_yaml_config: false) - end - - it { is_expected.to eq(value: 'value') } - end end context 'when config expand is true' do diff --git a/spec/lib/gitlab/ci/config/external/file/local_spec.rb b/spec/lib/gitlab/ci/config/external/file/local_spec.rb index f5b36ebfa45..a77acb45978 100644 --- a/spec/lib/gitlab/ci/config/external/file/local_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/local_spec.rb @@ -2,11 +2,13 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Config::External::File::Local do +RSpec.describe Gitlab::Ci::Config::External::File::Local, feature_category: :pipeline_authoring do + include RepoHelpers + let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } - let(:sha) { '12345' } + let(:sha) { project.commit.sha } let(:variables) { project.predefined_variables.to_runner_variables } let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) } let(:params) { { local: location } } @@ -172,14 +174,17 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local do let(:another_location) { 'another-config.yml' } let(:another_content) { 'rspec: JOB' } - before do - allow(project.repository).to receive(:blob_data_at).with(sha, location) - .and_return(content) - - allow(project.repository).to receive(:blob_data_at).with(sha, another_location) - .and_return(another_content) + let(:project_files) do + { + location => content, + another_location => another_content + } + end - local_file.validate! + around(:all) do |example| + create_and_delete_files(project, project_files) do + example.run + end end it 'does expand hash to include the template' do @@ -196,11 +201,11 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local do it { is_expected.to eq( context_project: project.full_path, - context_sha: '12345', + context_sha: sha, type: :local, - location: location, - blob: "http://localhost/#{project.full_path}/-/blob/12345/lib/gitlab/ci/templates/existent-file.yml", - raw: "http://localhost/#{project.full_path}/-/raw/12345/lib/gitlab/ci/templates/existent-file.yml", + location: '/lib/gitlab/ci/templates/existent-file.yml', + blob: "http://localhost/#{project.full_path}/-/blob/#{sha}/lib/gitlab/ci/templates/existent-file.yml", + raw: "http://localhost/#{project.full_path}/-/raw/#{sha}/lib/gitlab/ci/templates/existent-file.yml", extra: {} ) } diff --git a/spec/lib/gitlab/ci/config/external/mapper_spec.rb b/spec/lib/gitlab/ci/config/external/mapper_spec.rb index b7e58d4dfa1..9d0e57d4292 100644 --- a/spec/lib/gitlab/ci/config/external/mapper_spec.rb +++ b/spec/lib/gitlab/ci/config/external/mapper_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' -# This will be removed with FF ci_refactoring_external_mapper and moved to below. +# This will be use with the FF ci_refactoring_external_mapper_verifier in the next MR. +# It can be removed when the FF is removed. RSpec.shared_context 'gitlab_ci_config_external_mapper' do include StubRequests include RepoHelpers @@ -466,12 +467,4 @@ end RSpec.describe Gitlab::Ci::Config::External::Mapper, feature_category: :pipeline_authoring do it_behaves_like 'gitlab_ci_config_external_mapper' - - context 'when the FF ci_refactoring_external_mapper is disabled' do - before do - stub_feature_flags(ci_refactoring_external_mapper: false) - end - - it_behaves_like 'gitlab_ci_config_external_mapper' - end end |