summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/entry
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/config/entry')
-rw-r--r--spec/lib/gitlab/ci/config/entry/cache_spec.rb352
-rw-r--r--spec/lib/gitlab/ci/config/entry/caches_spec.rb70
-rw-r--r--spec/lib/gitlab/ci/config/entry/default_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/config/entry/hidden_spec.rb3
-rw-r--r--spec/lib/gitlab/ci/config/entry/job_spec.rb36
-rw-r--r--spec/lib/gitlab/ci/config/entry/kubernetes_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/entry/root_spec.rb127
7 files changed, 217 insertions, 374 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/cache_spec.rb b/spec/lib/gitlab/ci/config/entry/cache_spec.rb
index cec1c97085b..247f4b63910 100644
--- a/spec/lib/gitlab/ci/config/entry/cache_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/cache_spec.rb
@@ -7,295 +7,227 @@ RSpec.describe Gitlab::Ci::Config::Entry::Cache do
subject(:entry) { described_class.new(config) }
- context 'with multiple caches' do
+ describe 'validations' do
before do
entry.compose!
end
- describe '#valid?' do
- context 'with an empty hash as cache' do
- let(:config) { {} }
-
- it 'is valid' do
- expect(entry).to be_valid
- end
- end
-
- context 'when configuration is valid with a single cache' do
- let(:config) { { key: 'key', paths: ["logs/"], untracked: true } }
-
- it 'is valid' do
- expect(entry).to be_valid
+ context 'when entry config value is correct' do
+ let(:policy) { nil }
+ let(:key) { 'some key' }
+ let(:when_config) { nil }
+
+ let(:config) do
+ {
+ key: key,
+ untracked: true,
+ paths: ['some/path/']
+ }.tap do |config|
+ config[:policy] = policy if policy
+ config[:when] = when_config if when_config
end
end
- context 'when configuration is valid with multiple caches' do
- let(:config) do
- [
- { key: 'key', paths: ["logs/"], untracked: true },
- { key: 'key2', paths: ["logs/"], untracked: true },
- { key: 'key3', paths: ["logs/"], untracked: true }
- ]
+ 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')
+ end
end
- it 'is valid' do
- expect(entry).to be_valid
- end
- end
+ it_behaves_like 'hash key value'
- context 'when configuration is not a Hash or Array' do
- let(:config) { 'invalid' }
+ context 'with files' do
+ let(:key) { { files: %w[a-file other-file] } }
- it 'is invalid' do
- expect(entry).not_to be_valid
+ it_behaves_like 'hash key value'
end
- end
- context 'when entry values contain more than four caches' do
- let(:config) do
- [
- { key: 'key', paths: ["logs/"], untracked: true },
- { key: 'key2', paths: ["logs/"], untracked: true },
- { key: 'key3', paths: ["logs/"], untracked: true },
- { key: 'key4', paths: ["logs/"], untracked: true },
- { key: 'key5', paths: ["logs/"], untracked: true }
- ]
- end
+ context 'with files and prefix' do
+ let(:key) { { files: %w[a-file other-file], prefix: 'prefix-value' } }
- it 'is invalid' do
- expect(entry.errors).to eq(["caches config no more than 4 caches can be created"])
- expect(entry).not_to be_valid
+ it_behaves_like 'hash key value'
end
- end
- end
- end
- context 'with a single cache' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- end
- describe 'validations' do
- before do
- entry.compose!
- end
-
- context 'when entry config value is correct' do
- let(:policy) { nil }
- let(:key) { 'some key' }
- let(:when_config) { nil }
+ context 'with prefix' do
+ let(:key) { { prefix: 'prefix-value' } }
- let(:config) do
- {
- key: key,
- untracked: true,
- paths: ['some/path/']
- }.tap do |config|
- config[:policy] = policy if policy
- config[:when] = when_config if when_config
+ it 'key is nil' do
+ expect(entry.value).to match(a_hash_including(key: nil))
end
end
- 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')
- end
- end
-
- it_behaves_like 'hash key value'
-
- context 'with files' do
- let(:key) { { files: %w[a-file other-file] } }
-
- it_behaves_like 'hash key value'
- end
-
- context 'with files and prefix' do
- let(:key) { { files: %w[a-file other-file], prefix: 'prefix-value' } }
-
- it_behaves_like 'hash key value'
+ context 'with `policy`' do
+ where(:policy, :result) do
+ 'pull-push' | 'pull-push'
+ 'push' | 'push'
+ 'pull' | 'pull'
+ 'unknown' | 'unknown' # invalid
end
- context 'with prefix' do
- let(:key) { { prefix: 'prefix-value' } }
-
- it 'key is nil' do
- expect(entry.value).to match(a_hash_including(key: nil))
- end
+ with_them do
+ it { expect(entry.value).to include(policy: result) }
end
+ end
- context 'with `policy`' do
- where(:policy, :result) do
- 'pull-push' | 'pull-push'
- 'push' | 'push'
- 'pull' | 'pull'
- 'unknown' | 'unknown' # invalid
- end
-
- with_them do
- it { expect(entry.value).to include(policy: result) }
- end
+ context 'without `policy`' do
+ it 'assigns policy to default' do
+ expect(entry.value).to include(policy: 'pull-push')
end
+ end
- context 'without `policy`' do
- it 'assigns policy to default' do
- expect(entry.value).to include(policy: 'pull-push')
- end
+ context 'with `when`' do
+ where(:when_config, :result) do
+ 'on_success' | 'on_success'
+ 'on_failure' | 'on_failure'
+ 'always' | 'always'
+ 'unknown' | 'unknown' # invalid
end
- context 'with `when`' do
- where(:when_config, :result) do
- 'on_success' | 'on_success'
- 'on_failure' | 'on_failure'
- 'always' | 'always'
- 'unknown' | 'unknown' # invalid
- end
-
- with_them do
- it { expect(entry.value).to include(when: result) }
- end
+ with_them do
+ it { expect(entry.value).to include(when: result) }
end
+ end
- context 'without `when`' do
- it 'assigns when to default' do
- expect(entry.value).to include(when: 'on_success')
- end
+ context 'without `when`' do
+ it 'assigns when to default' do
+ expect(entry.value).to include(when: 'on_success')
end
end
+ end
- describe '#valid?' do
- it { is_expected.to be_valid }
+ describe '#valid?' do
+ it { is_expected.to be_valid }
- context 'with files' do
- let(:key) { { files: %w[a-file other-file] } }
+ context 'with files' do
+ let(:key) { { files: %w[a-file other-file] } }
- it { is_expected.to be_valid }
- end
+ it { is_expected.to be_valid }
end
+ end
- context 'with `policy`' do
- where(:policy, :valid) do
- 'pull-push' | true
- 'push' | true
- 'pull' | true
- 'unknown' | false
- end
+ context 'with `policy`' do
+ where(:policy, :valid) do
+ 'pull-push' | true
+ 'push' | true
+ 'pull' | true
+ 'unknown' | false
+ end
- with_them do
- it 'returns expected validity' do
- expect(entry.valid?).to eq(valid)
- end
+ with_them do
+ it 'returns expected validity' do
+ expect(entry.valid?).to eq(valid)
end
end
+ end
- context 'with `when`' do
- where(:when_config, :valid) do
- 'on_success' | true
- 'on_failure' | true
- 'always' | true
- 'unknown' | false
- end
+ context 'with `when`' do
+ where(:when_config, :valid) do
+ 'on_success' | true
+ 'on_failure' | true
+ 'always' | true
+ 'unknown' | false
+ end
- with_them do
- it 'returns expected validity' do
- expect(entry.valid?).to eq(valid)
- end
+ with_them do
+ it 'returns expected validity' do
+ expect(entry.valid?).to eq(valid)
end
end
+ end
- context 'with key missing' do
- let(:config) do
- { untracked: true,
- paths: ['some/path/'] }
- end
+ context 'with key missing' do
+ let(:config) do
+ { untracked: true,
+ paths: ['some/path/'] }
+ end
- describe '#value' do
- it 'sets key with the default' do
- expect(entry.value[:key])
- .to eq(Gitlab::Ci::Config::Entry::Key.default)
- end
+ describe '#value' do
+ it 'sets key with the default' do
+ expect(entry.value[:key])
+ .to eq(Gitlab::Ci::Config::Entry::Key.default)
end
end
end
+ end
- context 'when entry value is not correct' do
- describe '#errors' do
- subject { entry.errors }
+ context 'when entry value is not correct' do
+ describe '#errors' do
+ subject { entry.errors }
- context 'when is not a hash' do
- let(:config) { 'ls' }
+ context 'when is not a hash' do
+ let(:config) { 'ls' }
- it 'reports errors with config value' do
- is_expected.to include 'cache config should be a hash'
- end
+ it 'reports errors with config value' do
+ is_expected.to include 'cache config should be a hash'
end
+ end
- context 'when policy is unknown' do
- let(:config) { { policy: 'unknown' } }
+ context 'when policy is unknown' do
+ let(:config) { { policy: 'unknown' } }
- it 'reports error' do
- is_expected.to include('cache policy should be pull-push, push, or pull')
- end
+ it 'reports error' do
+ is_expected.to include('cache policy should be pull-push, push, or pull')
end
+ end
- context 'when `when` is unknown' do
- let(:config) { { when: 'unknown' } }
+ context 'when `when` is unknown' do
+ let(:config) { { when: 'unknown' } }
- it 'reports error' do
- is_expected.to include('cache when should be on_success, on_failure or always')
- end
+ it 'reports error' do
+ is_expected.to include('cache when should be on_success, on_failure or always')
end
+ end
- context 'when descendants are invalid' do
- context 'with invalid keys' do
- let(:config) { { key: 1 } }
-
- it 'reports error with descendants' do
- is_expected.to include 'key should be a hash, a string or a symbol'
- end
- end
-
- context 'with empty key' do
- let(:config) { { key: {} } }
+ context 'when descendants are invalid' do
+ context 'with invalid keys' do
+ let(:config) { { key: 1 } }
- it 'reports error with descendants' do
- is_expected.to include 'key config missing required keys: files'
- end
+ it 'reports error with descendants' do
+ is_expected.to include 'key should be a hash, a string or a symbol'
end
+ end
- context 'with invalid files' do
- let(:config) { { key: { files: 'a-file' } } }
+ context 'with empty key' do
+ let(:config) { { key: {} } }
- it 'reports error with descendants' do
- is_expected.to include 'key:files config should be an array of strings'
- end
+ it 'reports error with descendants' do
+ is_expected.to include 'key config missing required keys: files'
end
+ end
- context 'with prefix without files' do
- let(:config) { { key: { prefix: 'a-prefix' } } }
+ context 'with invalid files' do
+ let(:config) { { key: { files: 'a-file' } } }
- it 'reports error with descendants' do
- is_expected.to include 'key config missing required keys: files'
- end
+ it 'reports error with descendants' do
+ is_expected.to include 'key:files config should be an array of strings'
end
+ end
- context 'when there is an unknown key present' do
- let(:config) { { key: { unknown: 'a-file' } } }
+ context 'with prefix without files' do
+ let(:config) { { key: { prefix: 'a-prefix' } } }
- it 'reports error with descendants' do
- is_expected.to include 'key config contains unknown keys: unknown'
- end
+ it 'reports error with descendants' do
+ is_expected.to include 'key config missing required keys: files'
end
end
context 'when there is an unknown key present' do
- let(:config) { { invalid: true } }
+ let(:config) { { key: { unknown: 'a-file' } } }
it 'reports error with descendants' do
- is_expected.to include 'cache config contains unknown keys: invalid'
+ is_expected.to include 'key config contains unknown keys: unknown'
end
end
end
+
+ context 'when there is an unknown key present' do
+ let(:config) { { invalid: true } }
+
+ it 'reports error with descendants' do
+ is_expected.to include 'cache config contains unknown keys: invalid'
+ end
+ end
end
end
end
diff --git a/spec/lib/gitlab/ci/config/entry/caches_spec.rb b/spec/lib/gitlab/ci/config/entry/caches_spec.rb
new file mode 100644
index 00000000000..047cef53b96
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/entry/caches_spec.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Ci::Config::Entry::Caches do
+ using RSpec::Parameterized::TableSyntax
+
+ subject(:entry) { described_class.new(config) }
+
+ before do
+ entry.compose!
+ end
+
+ describe '#valid?' do
+ context 'with an empty hash as cache' do
+ let(:config) { {} }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+
+ context 'when configuration is valid with a single cache' do
+ let(:config) { { key: 'key', paths: ["logs/"], untracked: true } }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+
+ context 'when configuration is valid with multiple caches' do
+ let(:config) do
+ [
+ { key: 'key', paths: ["logs/"], untracked: true },
+ { key: 'key2', paths: ["logs/"], untracked: true },
+ { key: 'key3', paths: ["logs/"], untracked: true }
+ ]
+ end
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+
+ context 'when configuration is not a Hash or Array' do
+ let(:config) { 'invalid' }
+
+ it 'is invalid' do
+ expect(entry).not_to be_valid
+ end
+ end
+
+ context 'when entry values contain more than four caches' do
+ let(:config) do
+ [
+ { key: 'key', paths: ["logs/"], untracked: true },
+ { key: 'key2', paths: ["logs/"], untracked: true },
+ { key: 'key3', paths: ["logs/"], untracked: true },
+ { key: 'key4', paths: ["logs/"], untracked: true },
+ { key: 'key5', paths: ["logs/"], untracked: true }
+ ]
+ end
+
+ it 'is invalid' do
+ expect(entry.errors).to eq(["caches config no more than 4 caches can be created"])
+ expect(entry).not_to be_valid
+ end
+ end
+ 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 6e46d02a96e..5613b0f09d1 100644
--- a/spec/lib/gitlab/ci/config/entry/default_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/default_spec.rb
@@ -3,6 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Entry::Default do
+ let(:config) { {} }
let(:entry) { described_class.new(config) }
it_behaves_like 'with inheritable CI config' do
diff --git a/spec/lib/gitlab/ci/config/entry/hidden_spec.rb b/spec/lib/gitlab/ci/config/entry/hidden_spec.rb
index 090ef67f39d..7a2ecee0dae 100644
--- a/spec/lib/gitlab/ci/config/entry/hidden_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/hidden_spec.rb
@@ -20,6 +20,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Hidden do
end
describe '.new' do
+ let(:config) { {} }
let(:entry) { described_class.new(config) }
describe 'validations' do
@@ -41,8 +42,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Hidden do
context 'when entry value is not correct' do
context 'when config is empty' do
- let(:config) { {} }
-
describe '#valid' do
it 'is invalid' do
expect(entry).not_to be_valid
diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb
index ffcd029172a..1d23ab0c2c7 100644
--- a/spec/lib/gitlab/ci/config/entry/job_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb
@@ -556,42 +556,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do
end
end
- context 'with multiple_cache_per_job FF disabled' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- end
-
- context 'when job config overrides default config' do
- before do
- entry.compose!(deps)
- end
-
- let(:config) do
- { script: 'rspec', image: 'some_image', cache: { key: 'test' } }
- end
-
- 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')
- end
- end
-
- context 'when job config does not override default config' do
- before do
- allow(default).to receive('[]').with(:image).and_return(specified)
-
- entry.compose!(deps)
- end
-
- let(:config) { { script: 'ls', cache: { key: 'test' } } }
-
- 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')
- end
- end
- end
-
context 'with workflow rules' do
using RSpec::Parameterized::TableSyntax
diff --git a/spec/lib/gitlab/ci/config/entry/kubernetes_spec.rb b/spec/lib/gitlab/ci/config/entry/kubernetes_spec.rb
index 53809d2d549..0ac8d01b8e4 100644
--- a/spec/lib/gitlab/ci/config/entry/kubernetes_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/kubernetes_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Entry::Kubernetes do
+ let(:config) { Hash(namespace: 'namespace') }
+
subject { described_class.new(config) }
describe 'attributes' do
diff --git a/spec/lib/gitlab/ci/config/entry/root_spec.rb b/spec/lib/gitlab/ci/config/entry/root_spec.rb
index 041eb748fc9..31e3545e8d8 100644
--- a/spec/lib/gitlab/ci/config/entry/root_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/root_spec.rb
@@ -175,68 +175,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
)
end
end
-
- context 'with multuple_cache_per_job FF disabled' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- root.compose!
- end
-
- describe '#jobs_value' do
- it 'returns jobs configuration' do
- expect(root.jobs_value.keys).to eq([:rspec, :spinach, :release])
- expect(root.jobs_value[:rspec]).to eq(
- { name: :rspec,
- script: %w[rspec ls],
- before_script: %w(ls pwd),
- image: { name: 'ruby:2.7' },
- services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }],
- stage: 'test',
- cache: { key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' },
- variables: { 'VAR' => 'root', 'VAR2' => 'val 2' },
- job_variables: {},
- root_variables_inheritance: true,
- ignore: false,
- after_script: ['make clean'],
- only: { refs: %w[branches tags] },
- scheduling_type: :stage }
- )
- expect(root.jobs_value[:spinach]).to eq(
- { name: :spinach,
- before_script: [],
- script: %w[spinach],
- image: { name: 'ruby:2.7' },
- services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }],
- stage: 'test',
- cache: { key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' },
- variables: { 'VAR' => 'root', 'VAR2' => 'val 2' },
- job_variables: {},
- root_variables_inheritance: true,
- ignore: false,
- after_script: ['make clean'],
- only: { refs: %w[branches tags] },
- scheduling_type: :stage }
- )
- expect(root.jobs_value[:release]).to eq(
- { name: :release,
- stage: 'release',
- before_script: [],
- script: ["make changelog | tee release_changelog.txt"],
- release: { name: "Release $CI_TAG_NAME", tag_name: 'v0.06', description: "./release_changelog.txt" },
- image: { name: "ruby:2.7" },
- services: [{ name: "postgres:9.1" }, { name: "mysql:5.5" }],
- cache: { key: "k", untracked: true, paths: ["public/"], policy: "pull-push", when: 'on_success' },
- only: { refs: %w(branches tags) },
- variables: { 'VAR' => 'job', 'VAR2' => 'val 2' },
- job_variables: { 'VAR' => 'job' },
- root_variables_inheritance: true,
- after_script: [],
- ignore: false,
- scheduling_type: :stage }
- )
- end
- end
- end
end
end
@@ -255,56 +193,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
spinach: { before_script: [], variables: { VAR: 'job' }, script: 'spinach' } }
end
- context 'with multiple_cache_per_job FF disabled' do
- context 'when composed' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- root.compose!
- end
-
- describe '#errors' do
- it 'has no errors' do
- expect(root.errors).to be_empty
- end
- end
-
- describe '#jobs_value' do
- it 'returns jobs configuration' do
- expect(root.jobs_value).to eq(
- rspec: { name: :rspec,
- script: %w[rspec ls],
- before_script: %w(ls pwd),
- image: { name: 'ruby:2.7' },
- services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }],
- stage: 'test',
- cache: { key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' },
- variables: { 'VAR' => 'root' },
- job_variables: {},
- root_variables_inheritance: true,
- ignore: false,
- after_script: ['make clean'],
- only: { refs: %w[branches tags] },
- scheduling_type: :stage },
- spinach: { name: :spinach,
- before_script: [],
- script: %w[spinach],
- image: { name: 'ruby:2.7' },
- services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }],
- stage: 'test',
- cache: { key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' },
- variables: { 'VAR' => 'job' },
- job_variables: { 'VAR' => 'job' },
- root_variables_inheritance: true,
- ignore: false,
- after_script: ['make clean'],
- only: { refs: %w[branches tags] },
- scheduling_type: :stage }
- )
- end
- end
- end
- end
-
context 'when composed' do
before do
root.compose!
@@ -390,19 +278,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
expect(root.cache_value).to eq([key: 'a', policy: 'pull-push', when: 'on_success'])
end
end
-
- context 'with multiple_cache_per_job FF disabled' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- root.compose!
- end
-
- describe '#cache_value' do
- it 'returns correct cache definition' do
- expect(root.cache_value).to eq(key: 'a', policy: 'pull-push', when: 'on_success')
- end
- end
- end
end
context 'when variables resembles script-type job' do
@@ -525,7 +400,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
context 'when entry exists' do
it 'returns correct entry' do
expect(root[:cache])
- .to be_an_instance_of Gitlab::Ci::Config::Entry::Cache
+ .to be_an_instance_of Gitlab::Ci::Config::Entry::Caches
expect(root[:jobs][:rspec][:script].value).to eq ['ls']
end
end