diff options
Diffstat (limited to 'spec/lib/gitlab/ci/config/entry')
4 files changed, 128 insertions, 15 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/inherit/default_spec.rb b/spec/lib/gitlab/ci/config/entry/inherit/default_spec.rb new file mode 100644 index 00000000000..073f93ce542 --- /dev/null +++ b/spec/lib/gitlab/ci/config/entry/inherit/default_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::Gitlab::Ci::Config::Entry::Inherit::Default do + using RSpec::Parameterized::TableSyntax + + subject { described_class.new(config) } + + context 'validations' do + where(:config, :valid) do + true | true + false | true + %w[image] | true + %w[unknown] | false + %i[image] | false + [true] | false + "string" | false + end + + with_them do + it do + expect(subject.valid?).to eq(valid) + end + end + end + + describe '#inherit?' do + where(:config, :inherit) do + true | true + false | false + %w[image] | true + %w[before_script] | false + end + + with_them do + it do + expect(subject.inherit?('image')).to eq(inherit) + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/entry/inherit/variables_spec.rb b/spec/lib/gitlab/ci/config/entry/inherit/variables_spec.rb new file mode 100644 index 00000000000..06deed11c15 --- /dev/null +++ b/spec/lib/gitlab/ci/config/entry/inherit/variables_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::Gitlab::Ci::Config::Entry::Inherit::Variables do + using RSpec::Parameterized::TableSyntax + + subject { described_class.new(config) } + + context 'validations' do + where(:config, :valid) do + true | true + false | true + %w[A] | true + %w[A B] | true + %i[image] | true + [true] | false + "string" | false + end + + with_them do + it do + expect(subject.valid?).to eq(valid) + end + end + end + + describe '#inherit?' do + where(:config, :inherit) do + true | true + false | false + %w[A] | true + %w[B] | false + end + + with_them do + it do + expect(subject.inherit?('A')).to eq(inherit) + 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 7df0eccb3ed..b6279485426 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -18,7 +18,7 @@ describe Gitlab::Ci::Config::Entry::Job do end before do - allow(entry).to receive_message_chain(:inherit_entry, :default_value).and_return(true) + allow(entry).to receive_message_chain(:inherit_entry, :default_entry, :inherit?).and_return(true) 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 5c2c6520f25..8447a29c772 100644 --- a/spec/lib/gitlab/ci/config/entry/processable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/processable_spec.rb @@ -269,13 +269,13 @@ describe Gitlab::Ci::Config::Entry::Processable do context 'when root yaml variables are used' do let(:variables) do Gitlab::Ci::Config::Entry::Variables.new( - A: 'root', C: 'root' + A: 'root', C: 'root', D: 'root' ).value end it 'does return all variables and overwrite them' do expect(entry.value).to include( - variables: { 'A' => 'job', 'B' => 'job', 'C' => 'root' } + variables: { 'A' => 'job', 'B' => 'job', 'C' => 'root', 'D' => 'root' } ) end @@ -293,32 +293,61 @@ describe Gitlab::Ci::Config::Entry::Processable do ) end end + + context 'when inherit of only specific variable is enabled' do + let(:config) do + { + variables: { A: 'job', B: 'job' }, + inherit: { variables: ['D'] } + } + end + + it 'does return only job variables' do + expect(entry.value).to include( + variables: { 'A' => 'job', 'B' => 'job', 'D' => 'root' } + ) + end + end end end context 'of default:tags' do using RSpec::Parameterized::TableSyntax - where(:default_tags, :tags, :inherit_default, :result) do - nil | %w[a b] | nil | %w[a b] - nil | %w[a b] | true | %w[a b] - nil | %w[a b] | false | %w[a b] - %w[b c] | %w[a b] | nil | %w[a b] - %w[b c] | %w[a b] | true | %w[a b] - %w[b c] | %w[a b] | false | %w[a b] - %w[b c] | nil | nil | %w[b c] - %w[b c] | nil | true | %w[b c] - %w[b c] | nil | false | nil + where(:name, :default_tags, :tags, :inherit_default, :result) do + "only local tags" | nil | %w[a b] | nil | %w[a b] + "only local tags" | nil | %w[a b] | true | %w[a b] + "only local tags" | nil | %w[a b] | false | %w[a b] + "global and local tags" | %w[b c] | %w[a b] | nil | %w[a b] + "global and local tags" | %w[b c] | %w[a b] | true | %w[a b] + "global and local tags" | %w[b c] | %w[a b] | false | %w[a b] + "only global tags" | %w[b c] | nil | nil | %w[b c] + "only global tags" | %w[b c] | nil | true | %w[b c] + "only global tags" | %w[b c] | nil | false | nil + "only global tags" | %w[b c] | nil | %w[image] | nil + "only global tags" | %w[b c] | nil | %w[tags] | %w[b c] end with_them do - let(:config) { { tags: tags, inherit: { default: inherit_default } } } - let(:default_specified_tags) { double('tags', 'specified?' => true, 'valid?' => true, 'value' => default_tags) } + let(:config) do + { tags: tags, + inherit: { default: inherit_default } } + end + + let(:default_specified_tags) do + double('tags', + 'specified?' => true, + 'valid?' => true, + 'value' => default_tags, + 'errors' => []) + end before do allow(default).to receive('[]').with(:tags).and_return(default_specified_tags) entry.compose!(deps) + + expect(entry).to be_valid end it { expect(entry.tags_value).to eq(result) } |