Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 15:08:16 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 15:08:16 +0300
commit1fa79760ad2d4bd67f5c5a27f372a7533b9b7c69 (patch)
treeffdfbd9113743831ff4f1290959a62cf6567fde5 /spec/lib/gitlab/ci
parent82fa8a3d1e8466ef36b58604d20fcc145ea12118 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/ci')
-rw-r--r--spec/lib/gitlab/ci/config/entry/inherit/default_spec.rb42
-rw-r--r--spec/lib/gitlab/ci/config/entry/inherit/variables_spec.rb42
-rw-r--r--spec/lib/gitlab/ci/config/entry/job_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/entry/processable_spec.rb57
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb48
5 files changed, 160 insertions, 31 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) }
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index 5c85a136972..af0a85f6c4e 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -515,6 +515,8 @@ module Gitlab
nil | ["global script"]
{ default: false } | nil
{ default: true } | ["global script"]
+ { default: %w[before_script] } | ["global script"]
+ { default: %w[image] } | nil
end
with_them do
@@ -527,26 +529,28 @@ module Gitlab
it { expect(subject[:options][:before_script]).to eq(result) }
end
- end
- context "in default context" do
- using RSpec::Parameterized::TableSyntax
+ context "in default context" do
+ using RSpec::Parameterized::TableSyntax
- where(:inherit, :result) do
- nil | ["global script"]
- { default: false } | nil
- { default: true } | ["global script"]
- end
-
- with_them do
- let(:config) do
- {
- default: { before_script: ["global script"] },
- test: { script: ["script"], inherit: inherit }
- }
+ where(:inherit, :result) do
+ nil | ["global script"]
+ { default: false } | nil
+ { default: true } | ["global script"]
+ { default: %w[before_script] } | ["global script"]
+ { default: %w[image] } | nil
end
- it { expect(subject[:options][:before_script]).to eq(result) }
+ with_them do
+ let(:config) do
+ {
+ default: { before_script: ["global script"] },
+ test: { script: ["script"], inherit: inherit }
+ }
+ end
+
+ it { expect(subject[:options][:before_script]).to eq(result) }
+ end
end
end
@@ -845,6 +849,18 @@ module Gitlab
)
end
end
+
+ context 'when specific variables are to inherited' do
+ let(:inherit) { { variables: %w[VAR1 VAR4] } }
+
+ it 'returns all unique variables and inherits only specified variables' do
+ expect(subject).to contain_exactly(
+ { key: 'VAR4', value: 'global4', public: true },
+ { key: 'VAR1', value: 'value1', public: true },
+ { key: 'VAR2', value: 'value2', public: true }
+ )
+ end
+ end
end
context 'when job variables are defined' do