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>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /spec/lib/gitlab/ci
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/lib/gitlab/ci')
-rw-r--r--spec/lib/gitlab/ci/build/cache_spec.rb98
-rw-r--r--spec/lib/gitlab/ci/build/policy/changes_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/build/releaser_spec.rb12
-rw-r--r--spec/lib/gitlab/ci/build/step_spec.rb2
-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
-rw-r--r--spec/lib/gitlab/ci/config/external/file/local_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/config/external/file/project_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/config/external/file/template_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/config/external/mapper_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/config/external/processor_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/build_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/limit/deployments_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb22
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb12
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/validate/external_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/validate/repository_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb247
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/build_spec.rb86
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/processable/resource_group_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/reports/codequality_mr_diff_spec.rb15
-rw-r--r--spec/lib/gitlab/ci/reports/codequality_reports_comparer_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/reports/test_failure_history_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/status/core_spec.rb17
-rw-r--r--spec/lib/gitlab/ci/syntax_templates_spec.rb25
-rw-r--r--spec/lib/gitlab/ci/templates/Jobs/build_gitlab_ci_yaml_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/templates/Jobs/deploy_gitlab_ci_yaml_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/templates/Verify/load_performance_testing_gitlab_ci_yaml_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/templates/templates_spec.rb34
-rw-r--r--spec/lib/gitlab/ci/trace/chunked_io_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/trace_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb149
43 files changed, 351 insertions, 990 deletions
diff --git a/spec/lib/gitlab/ci/build/cache_spec.rb b/spec/lib/gitlab/ci/build/cache_spec.rb
index 9188045988b..7477aedb994 100644
--- a/spec/lib/gitlab/ci/build/cache_spec.rb
+++ b/spec/lib/gitlab/ci/build/cache_spec.rb
@@ -4,11 +4,23 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Build::Cache do
describe '.initialize' do
- context 'when the multiple cache feature flag is disabled' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
+ context 'when the cache is an array' do
+ it 'instantiates an array of cache seeds' do
+ cache_config = [{ key: 'key-a' }, { key: 'key-b' }]
+ pipeline = double(::Ci::Pipeline)
+ cache_seed_a = double(Gitlab::Ci::Pipeline::Seed::Build::Cache)
+ cache_seed_b = double(Gitlab::Ci::Pipeline::Seed::Build::Cache)
+ allow(Gitlab::Ci::Pipeline::Seed::Build::Cache).to receive(:new).and_return(cache_seed_a, cache_seed_b)
+
+ cache = described_class.new(cache_config, pipeline)
+
+ expect(Gitlab::Ci::Pipeline::Seed::Build::Cache).to have_received(:new).with(pipeline, { key: 'key-a' })
+ expect(Gitlab::Ci::Pipeline::Seed::Build::Cache).to have_received(:new).with(pipeline, { key: 'key-b' })
+ expect(cache.instance_variable_get(:@cache)).to eq([cache_seed_a, cache_seed_b])
end
+ end
+ context 'when the cache is a hash' do
it 'instantiates a cache seed' do
cache_config = { key: 'key-a' }
pipeline = double(::Ci::Pipeline)
@@ -18,87 +30,35 @@ RSpec.describe Gitlab::Ci::Build::Cache do
cache = described_class.new(cache_config, pipeline)
expect(Gitlab::Ci::Pipeline::Seed::Build::Cache).to have_received(:new).with(pipeline, cache_config)
- expect(cache.instance_variable_get(:@cache)).to eq(cache_seed)
- end
- end
-
- context 'when the multiple cache feature flag is enabled' do
- context 'when the cache is an array' do
- it 'instantiates an array of cache seeds' do
- cache_config = [{ key: 'key-a' }, { key: 'key-b' }]
- pipeline = double(::Ci::Pipeline)
- cache_seed_a = double(Gitlab::Ci::Pipeline::Seed::Build::Cache)
- cache_seed_b = double(Gitlab::Ci::Pipeline::Seed::Build::Cache)
- allow(Gitlab::Ci::Pipeline::Seed::Build::Cache).to receive(:new).and_return(cache_seed_a, cache_seed_b)
-
- cache = described_class.new(cache_config, pipeline)
-
- expect(Gitlab::Ci::Pipeline::Seed::Build::Cache).to have_received(:new).with(pipeline, { key: 'key-a' })
- expect(Gitlab::Ci::Pipeline::Seed::Build::Cache).to have_received(:new).with(pipeline, { key: 'key-b' })
- expect(cache.instance_variable_get(:@cache)).to eq([cache_seed_a, cache_seed_b])
- end
- end
-
- context 'when the cache is a hash' do
- it 'instantiates a cache seed' do
- cache_config = { key: 'key-a' }
- pipeline = double(::Ci::Pipeline)
- cache_seed = double(Gitlab::Ci::Pipeline::Seed::Build::Cache)
- allow(Gitlab::Ci::Pipeline::Seed::Build::Cache).to receive(:new).and_return(cache_seed)
-
- cache = described_class.new(cache_config, pipeline)
-
- expect(Gitlab::Ci::Pipeline::Seed::Build::Cache).to have_received(:new).with(pipeline, cache_config)
- expect(cache.instance_variable_get(:@cache)).to eq([cache_seed])
- end
+ expect(cache.instance_variable_get(:@cache)).to eq([cache_seed])
end
end
end
describe '#cache_attributes' do
- context 'when the multiple cache feature flag is disabled' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- end
-
- it "returns the cache seed's build attributes" do
- cache_config = { key: 'key-a' }
+ context 'when there are no caches' do
+ it 'returns an empty hash' do
+ cache_config = []
pipeline = double(::Ci::Pipeline)
cache = described_class.new(cache_config, pipeline)
attributes = cache.cache_attributes
- expect(attributes).to eq({
- options: { cache: { key: 'key-a' } }
- })
+ expect(attributes).to eq({})
end
end
- context 'when the multiple cache feature flag is enabled' do
- context 'when there are no caches' do
- it 'returns an empty hash' do
- cache_config = []
- pipeline = double(::Ci::Pipeline)
- cache = described_class.new(cache_config, pipeline)
-
- attributes = cache.cache_attributes
-
- expect(attributes).to eq({})
- end
- end
-
- context 'when there are caches' do
- it 'returns the structured attributes for the caches' do
- cache_config = [{ key: 'key-a' }, { key: 'key-b' }]
- pipeline = double(::Ci::Pipeline)
- cache = described_class.new(cache_config, pipeline)
+ context 'when there are caches' do
+ it 'returns the structured attributes for the caches' do
+ cache_config = [{ key: 'key-a' }, { key: 'key-b' }]
+ pipeline = double(::Ci::Pipeline)
+ cache = described_class.new(cache_config, pipeline)
- attributes = cache.cache_attributes
+ attributes = cache.cache_attributes
- expect(attributes).to eq({
- options: { cache: cache_config }
- })
- end
+ expect(attributes).to eq({
+ options: { cache: cache_config }
+ })
end
end
end
diff --git a/spec/lib/gitlab/ci/build/policy/changes_spec.rb b/spec/lib/gitlab/ci/build/policy/changes_spec.rb
index 016730e01cd..5d5a212b9a5 100644
--- a/spec/lib/gitlab/ci/build/policy/changes_spec.rb
+++ b/spec/lib/gitlab/ci/build/policy/changes_spec.rb
@@ -120,6 +120,7 @@ RSpec.describe Gitlab::Ci::Build::Policy::Changes do
context 'when branch is created' do
let_it_be(:project) { create(:project, :repository) }
+
let(:pipeline) do
create(:ci_empty_pipeline, project: project,
ref: 'feature',
diff --git a/spec/lib/gitlab/ci/build/releaser_spec.rb b/spec/lib/gitlab/ci/build/releaser_spec.rb
index fa5e90674a6..435f70e9ac5 100644
--- a/spec/lib/gitlab/ci/build/releaser_spec.rb
+++ b/spec/lib/gitlab/ci/build/releaser_spec.rb
@@ -15,18 +15,25 @@ RSpec.describe Gitlab::Ci::Build::Releaser do
tag_name: 'release-$CI_COMMIT_SHA',
ref: '$CI_COMMIT_SHA',
milestones: %w[m1 m2 m3],
- released_at: '2020-07-15T08:00:00Z'
+ released_at: '2020-07-15T08:00:00Z',
+ assets: {
+ links: [
+ { name: 'asset1', url: 'https://example.com/assets/1', link_type: 'other', filepath: '/pretty/asset/1' },
+ { name: 'asset2', url: 'https://example.com/assets/2' }
+ ]
+ }
}
}
end
it 'generates the script' do
- expect(subject).to eq(['release-cli create --name "Release $CI_COMMIT_SHA" --description "Created using the release-cli $EXTRA_DESCRIPTION" --tag-name "release-$CI_COMMIT_SHA" --ref "$CI_COMMIT_SHA" --released-at "2020-07-15T08:00:00Z" --milestone "m1" --milestone "m2" --milestone "m3"'])
+ expect(subject).to eq(['release-cli create --name "Release $CI_COMMIT_SHA" --description "Created using the release-cli $EXTRA_DESCRIPTION" --tag-name "release-$CI_COMMIT_SHA" --ref "$CI_COMMIT_SHA" --released-at "2020-07-15T08:00:00Z" --milestone "m1" --milestone "m2" --milestone "m3" --assets-link "{\"name\":\"asset1\",\"url\":\"https://example.com/assets/1\",\"link_type\":\"other\",\"filepath\":\"/pretty/asset/1\"}" --assets-link "{\"name\":\"asset2\",\"url\":\"https://example.com/assets/2\"}"'])
end
end
context 'individual nodes' do
using RSpec::Parameterized::TableSyntax
+ links = { links: [{ name: 'asset1', url: 'https://example.com/assets/1', link_type: 'other', filepath: '/pretty/asset/1' }] }
where(:node_name, :node_value, :result) do
:name | 'Release $CI_COMMIT_SHA' | 'release-cli create --name "Release $CI_COMMIT_SHA"'
@@ -35,6 +42,7 @@ RSpec.describe Gitlab::Ci::Build::Releaser do
:ref | '$CI_COMMIT_SHA' | 'release-cli create --ref "$CI_COMMIT_SHA"'
:milestones | %w[m1 m2 m3] | 'release-cli create --milestone "m1" --milestone "m2" --milestone "m3"'
:released_at | '2020-07-15T08:00:00Z' | 'release-cli create --released-at "2020-07-15T08:00:00Z"'
+ :assets | links | "release-cli create --assets-link #{links[:links][0].to_json.to_json}"
end
with_them do
diff --git a/spec/lib/gitlab/ci/build/step_spec.rb b/spec/lib/gitlab/ci/build/step_spec.rb
index 4b8f68b9fa8..938b52c496c 100644
--- a/spec/lib/gitlab/ci/build/step_spec.rb
+++ b/spec/lib/gitlab/ci/build/step_spec.rb
@@ -62,7 +62,7 @@ RSpec.describe Gitlab::Ci::Build::Step do
let(:job) { create(:ci_build, :release_options) }
it 'returns the release-cli command line' do
- expect(subject.script).to eq(["release-cli create --name \"Release $CI_COMMIT_SHA\" --description \"Created using the release-cli $EXTRA_DESCRIPTION\" --tag-name \"release-$CI_COMMIT_SHA\" --ref \"$CI_COMMIT_SHA\""])
+ expect(subject.script).to eq(["release-cli create --name \"Release $CI_COMMIT_SHA\" --description \"Created using the release-cli $EXTRA_DESCRIPTION\" --tag-name \"release-$CI_COMMIT_SHA\" --ref \"$CI_COMMIT_SHA\" --assets-link \"{\\\"name\\\":\\\"asset1\\\",\\\"url\\\":\\\"https://example.com/assets/1\\\"}\""])
end
end
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
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 7e39fae7b9b..3d1fc32a62d 100644
--- a/spec/lib/gitlab/ci/config/external/file/local_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/file/local_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::External::File::Local do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
+
let(:sha) { '12345' }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
let(:params) { { local: location } }
diff --git a/spec/lib/gitlab/ci/config/external/file/project_spec.rb b/spec/lib/gitlab/ci/config/external/file/project_spec.rb
index 0e8851ba915..c53914c5772 100644
--- a/spec/lib/gitlab/ci/config/external/file/project_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/file/project_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Gitlab::Ci::Config::External::File::Project do
let_it_be(:context_project) { create(:project) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
+
let(:context_user) { user }
let(:parent_pipeline) { double(:parent_pipeline) }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
diff --git a/spec/lib/gitlab/ci/config/external/file/template_spec.rb b/spec/lib/gitlab/ci/config/external/file/template_spec.rb
index ad1d93a64a1..75b22c1516c 100644
--- a/spec/lib/gitlab/ci/config/external/file/template_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/file/template_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::External::File::Template do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
+
let(:context_params) { { project: project, sha: '12345', user: user } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
let(:template) { 'Auto-DevOps.gitlab-ci.yml' }
diff --git a/spec/lib/gitlab/ci/config/external/mapper_spec.rb b/spec/lib/gitlab/ci/config/external/mapper_spec.rb
index e5b008a482e..88097f3f56a 100644
--- a/spec/lib/gitlab/ci/config/external/mapper_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/mapper_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
+
let(:local_file) { '/lib/gitlab/ci/templates/non-existent-file.yml' }
let(:remote_url) { 'https://gitlab.com/gitlab-org/gitlab-foss/blob/1234/.gitlab-ci-1.yml' }
let(:template_file) { 'Auto-DevOps.gitlab-ci.yml' }
diff --git a/spec/lib/gitlab/ci/config/external/processor_spec.rb b/spec/lib/gitlab/ci/config/external/processor_spec.rb
index d657c3e943f..e032d372ecb 100644
--- a/spec/lib/gitlab/ci/config/external/processor_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/processor_spec.rb
@@ -8,6 +8,7 @@ RSpec.describe Gitlab::Ci::Config::External::Processor do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:another_project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
+
let(:sha) { '12345' }
let(:context_params) { { project: project, sha: sha, user: user } }
let(:context) { Gitlab::Ci::Config::External::Context.new(**context_params) }
diff --git a/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
index 53dea1d0d19..6019318a401 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Chain::Build do
let_it_be(:project, reload: true) { create(:project, :repository) }
let_it_be(:user) { create(:user, developer_projects: [project]) }
+
let(:pipeline) { Ci::Pipeline.new }
let(:variables_attributes) do
diff --git a/spec/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines_spec.rb
index 1d17244e519..2727f2603cd 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Chain::CancelPendingPipelines do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
+
let(:prev_pipeline) { create(:ci_pipeline, project: project) }
let(:new_commit) { create(:commit, project: project) }
let(:pipeline) { create(:ci_pipeline, project: project, sha: new_commit.sha) }
diff --git a/spec/lib/gitlab/ci/pipeline/chain/limit/deployments_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/limit/deployments_spec.rb
index 23cdec61bb3..499dc3554a3 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/limit/deployments_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/limit/deployments_spec.rb
@@ -74,7 +74,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Deployments do
it 'adds an informative error to the pipeline' do
perform
- expect(pipeline.errors.messages).to include(base: ['Pipeline has too many deployments! Requested 2, but the limit is 1.'])
+ expect(pipeline.errors.added?(:base, 'Pipeline has too many deployments! Requested 2, but the limit is 1.')).to be true
end
it 'increments the error metric' do
diff --git a/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb
index 264076859cb..2e537f40692 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb
@@ -218,15 +218,18 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Seed do
end
context 'N+1 queries' do
- it 'avoids N+1 queries when calculating variables of jobs' do
+ it 'avoids N+1 queries when calculating variables of jobs', :use_sql_query_cache do
+ warm_up_pipeline, warm_up_command = prepare_pipeline1
+ perform_seed(warm_up_pipeline, warm_up_command)
+
pipeline1, command1 = prepare_pipeline1
pipeline2, command2 = prepare_pipeline2
- control = ActiveRecord::QueryRecorder.new do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
perform_seed(pipeline1, command1)
end
- expect { perform_seed(pipeline2, command2) }.not_to exceed_query_limit(
+ expect { perform_seed(pipeline2, command2) }.not_to exceed_all_query_limit(
control.count + expected_extra_queries
)
end
@@ -259,15 +262,10 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Seed do
def expected_extra_queries
extra_jobs = 2
- non_handled_sql_queries = 3
-
- # 1. Ci::Build Load () SELECT "ci_builds".* FROM "ci_builds"
- # WHERE "ci_builds"."type" = 'Ci::Build'
- # AND "ci_builds"."commit_id" IS NULL
- # AND ("ci_builds"."retried" = FALSE OR "ci_builds"."retried" IS NULL)
- # AND (stage_idx < 1)
- # 2. Ci::InstanceVariable Load => `Ci::InstanceVariable#cached_data` => already cached with `fetch_memory_cache`
- # 3. Ci::Variable Load => `Project#ci_variables_for` => already cached with `Gitlab::SafeRequestStore`
+ non_handled_sql_queries = 2
+
+ # 1. Ci::InstanceVariable Load => `Ci::InstanceVariable#cached_data` => already cached with `fetch_memory_cache`
+ # 2. Ci::Variable Load => `Project#ci_variables_for` => already cached with `Gitlab::SafeRequestStore`
extra_jobs * non_handled_sql_queries
end
diff --git a/spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb
index e4768f2ef0d..27af8d379ef 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb
@@ -21,17 +21,25 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Skip do
before do
allow(pipeline).to receive(:git_commit_message)
.and_return('commit message [ci skip]')
-
- step.perform!
end
it 'breaks the chain' do
+ step.perform!
+
expect(step.break?).to be true
end
it 'skips the pipeline' do
+ step.perform!
+
expect(pipeline.reload).to be_skipped
end
+
+ it 'calls ensure_project_iid explicitly' do
+ expect(pipeline).to receive(:ensure_project_iid!)
+
+ step.perform!
+ end
end
context 'when pipeline has not been skipped' do
diff --git a/spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb
index cd868a57bbc..8e0b032e68c 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Chain::TemplateUsage do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
+
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:command) do
diff --git a/spec/lib/gitlab/ci/pipeline/chain/validate/external_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/validate/external_spec.rb
index caf3a053c4e..e3061f8095b 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/validate/external_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/validate/external_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
+
let(:pipeline) { build(:ci_empty_pipeline, user: user, project: project) }
let!(:step) { described_class.new(pipeline, command) }
diff --git a/spec/lib/gitlab/ci/pipeline/chain/validate/repository_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/validate/repository_spec.rb
index 7eefb4d7876..feedef18dcd 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/validate/repository_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/validate/repository_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::Repository do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
+
let(:pipeline) { build_stubbed(:ci_pipeline) }
let!(:step) { described_class.new(pipeline, command) }
diff --git a/spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb
index 773cb61b946..910c12389c3 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb
@@ -9,253 +9,6 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Build::Cache do
let(:processor) { described_class.new(pipeline, config) }
- context 'with multiple_cache_per_job ff disabled' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- end
-
- describe '#build_attributes' do
- subject { processor.build_attributes }
-
- context 'with cache:key' do
- let(:config) do
- {
- key: 'a-key',
- paths: ['vendor/ruby']
- }
- end
-
- it { is_expected.to include(options: { cache: config }) }
- end
-
- context 'with cache:key as a symbol' do
- let(:config) do
- {
- key: :a_key,
- paths: ['vendor/ruby']
- }
- end
-
- it { is_expected.to include(options: { cache: config.merge(key: "a_key") }) }
- end
-
- context 'with cache:key:files' do
- shared_examples 'default key' do
- let(:config) do
- { key: { files: files } }
- end
-
- it 'uses default key' do
- expected = { options: { cache: { key: 'default' } } }
-
- is_expected.to include(expected)
- end
- end
-
- shared_examples 'version and gemfile files' do
- let(:config) do
- {
- key: {
- files: files
- },
- paths: ['vendor/ruby']
- }
- end
-
- it 'builds a string key' do
- expected = {
- options: {
- cache: {
- key: '703ecc8fef1635427a1f86a8a1a308831c122392',
- paths: ['vendor/ruby']
- }
- }
- }
-
- is_expected.to include(expected)
- end
- end
-
- context 'with existing files' do
- let(:files) { ['VERSION', 'Gemfile.zip'] }
-
- it_behaves_like 'version and gemfile files'
- end
-
- context 'with files starting with ./' do
- let(:files) { ['Gemfile.zip', './VERSION'] }
-
- it_behaves_like 'version and gemfile files'
- end
-
- context 'with files ending with /' do
- let(:files) { ['Gemfile.zip/'] }
-
- it_behaves_like 'default key'
- end
-
- context 'with new line in filenames' do
- let(:files) { ["Gemfile.zip\nVERSION"] }
-
- it_behaves_like 'default key'
- end
-
- context 'with missing files' do
- let(:files) { ['project-gemfile.lock', ''] }
-
- it_behaves_like 'default key'
- end
-
- context 'with directories' do
- shared_examples 'foo/bar directory key' do
- let(:config) do
- {
- key: {
- files: files
- }
- }
- end
-
- it 'builds a string key' do
- expected = {
- options: {
- cache: { key: '74bf43fb1090f161bdd4e265802775dbda2f03d1' }
- }
- }
-
- is_expected.to include(expected)
- end
- end
-
- context 'with directory' do
- let(:files) { ['foo/bar'] }
-
- it_behaves_like 'foo/bar directory key'
- end
-
- context 'with directory ending in slash' do
- let(:files) { ['foo/bar/'] }
-
- it_behaves_like 'foo/bar directory key'
- end
-
- context 'with directories ending in slash star' do
- let(:files) { ['foo/bar/*'] }
-
- it_behaves_like 'foo/bar directory key'
- end
- end
- end
-
- context 'with cache:key:prefix' do
- context 'without files' do
- let(:config) do
- {
- key: {
- prefix: 'a-prefix'
- },
- paths: ['vendor/ruby']
- }
- end
-
- it 'adds prefix to default key' do
- expected = {
- options: {
- cache: {
- key: 'a-prefix-default',
- paths: ['vendor/ruby']
- }
- }
- }
-
- is_expected.to include(expected)
- end
- end
-
- context 'with existing files' do
- let(:config) do
- {
- key: {
- files: ['VERSION', 'Gemfile.zip'],
- prefix: 'a-prefix'
- },
- paths: ['vendor/ruby']
- }
- end
-
- it 'adds prefix key' do
- expected = {
- options: {
- cache: {
- key: 'a-prefix-703ecc8fef1635427a1f86a8a1a308831c122392',
- paths: ['vendor/ruby']
- }
- }
- }
-
- is_expected.to include(expected)
- end
- end
-
- context 'with missing files' do
- let(:config) do
- {
- key: {
- files: ['project-gemfile.lock', ''],
- prefix: 'a-prefix'
- },
- paths: ['vendor/ruby']
- }
- end
-
- it 'adds prefix to default key' do
- expected = {
- options: {
- cache: {
- key: 'a-prefix-default',
- paths: ['vendor/ruby']
- }
- }
- }
-
- is_expected.to include(expected)
- end
- end
- end
-
- context 'with all cache option keys' do
- let(:config) do
- {
- key: 'a-key',
- paths: ['vendor/ruby'],
- untracked: true,
- policy: 'push',
- when: 'on_success'
- }
- end
-
- it { is_expected.to include(options: { cache: config }) }
- end
-
- context 'with unknown cache option keys' do
- let(:config) do
- {
- key: 'a-key',
- unknown_key: true
- }
- end
-
- it { expect { subject }.to raise_error(ArgumentError, /unknown_key/) }
- end
-
- context 'with empty config' do
- let(:config) { {} }
-
- it { is_expected.to include(options: {}) }
- end
- end
- end
-
describe '#attributes' do
subject { processor.attributes }
diff --git a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
index f97935feb86..058fb25807d 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:head_sha) { project.repository.head_commit.id }
+
let(:pipeline) { build(:ci_empty_pipeline, project: project, sha: head_sha) }
let(:root_variables) { [] }
let(:seed_context) { double(pipeline: pipeline, root_variables: root_variables) }
@@ -89,91 +90,6 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do
end
end
- context 'with multiple_cache_per_job FF disabled' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- end
-
- context 'with cache:key' do
- let(:attributes) do
- {
- name: 'rspec',
- ref: 'master',
- cache: {
- key: 'a-value'
- }
- }
- end
-
- it { is_expected.to include(options: { cache: { key: 'a-value' } }) }
- end
-
- context 'with cache:key:files' do
- let(:attributes) do
- {
- name: 'rspec',
- ref: 'master',
- cache: {
- key: {
- files: ['VERSION']
- }
- }
- }
- end
-
- it 'includes cache options' do
- cache_options = {
- options: {
- cache: { key: 'f155568ad0933d8358f66b846133614f76dd0ca4' }
- }
- }
-
- is_expected.to include(cache_options)
- end
- end
-
- context 'with cache:key:prefix' do
- let(:attributes) do
- {
- name: 'rspec',
- ref: 'master',
- cache: {
- key: {
- prefix: 'something'
- }
- }
- }
- end
-
- it { is_expected.to include(options: { cache: { key: 'something-default' } }) }
- end
-
- context 'with cache:key:files and prefix' do
- let(:attributes) do
- {
- name: 'rspec',
- ref: 'master',
- cache: {
- key: {
- files: ['VERSION'],
- prefix: 'something'
- }
- }
- }
- end
-
- it 'includes cache options' do
- cache_options = {
- options: {
- cache: { key: 'something-f155568ad0933d8358f66b846133614f76dd0ca4' }
- }
- }
-
- is_expected.to include(cache_options)
- end
- end
- end
-
context 'with cache:key' do
let(:attributes) do
{
diff --git a/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb
index 1f38c7aec63..9f7281fb714 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Seed::Deployment do
let_it_be(:project, refind: true) { create(:project, :repository) }
+
let(:pipeline) do
create(:ci_pipeline, project: project,
sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0')
diff --git a/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb
index 99196d393c6..175b12637e6 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Seed::Environment do
let_it_be(:project) { create(:project) }
+
let(:job) { build(:ci_build, project: project) }
let(:seed) { described_class.new(job) }
let(:attributes) { {} }
diff --git a/spec/lib/gitlab/ci/pipeline/seed/processable/resource_group_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/processable/resource_group_spec.rb
index b7260599de2..9bd0e014873 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/processable/resource_group_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/processable/resource_group_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Seed::Processable::ResourceGroup do
let_it_be(:project) { create(:project) }
+
let(:job) { build(:ci_build, project: project) }
let(:seed) { described_class.new(job, resource_group_key) }
diff --git a/spec/lib/gitlab/ci/reports/codequality_mr_diff_spec.rb b/spec/lib/gitlab/ci/reports/codequality_mr_diff_spec.rb
index 8b177fa7fc1..73b916da2e9 100644
--- a/spec/lib/gitlab/ci/reports/codequality_mr_diff_spec.rb
+++ b/spec/lib/gitlab/ci/reports/codequality_mr_diff_spec.rb
@@ -9,14 +9,11 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityMrDiff do
let(:degradation_3) { build(:codequality_degradation_3) }
describe '#initialize!' do
- subject(:report) { described_class.new(codequality_report) }
+ subject(:report) { described_class.new(new_degradations) }
context 'when quality has degradations' do
context 'with several degradations on the same line' do
- before do
- codequality_report.add_degradation(degradation_1)
- codequality_report.add_degradation(degradation_2)
- end
+ let(:new_degradations) { [degradation_1, degradation_2] }
it 'generates quality report for mr diff' do
expect(report.files).to match(
@@ -29,11 +26,7 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityMrDiff do
end
context 'with several degradations on several files' do
- before do
- codequality_report.add_degradation(degradation_1)
- codequality_report.add_degradation(degradation_2)
- codequality_report.add_degradation(degradation_3)
- end
+ let(:new_degradations) { [degradation_1, degradation_2, degradation_3] }
it 'returns quality report for mr diff' do
expect(report.files).to match(
@@ -50,6 +43,8 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityMrDiff do
end
context 'when quality has no degradation' do
+ let(:new_degradations) { [] }
+
it 'returns an empty hash' do
expect(report.files).to match({})
end
diff --git a/spec/lib/gitlab/ci/reports/codequality_reports_comparer_spec.rb b/spec/lib/gitlab/ci/reports/codequality_reports_comparer_spec.rb
index 8378d096fcf..e289e59b281 100644
--- a/spec/lib/gitlab/ci/reports/codequality_reports_comparer_spec.rb
+++ b/spec/lib/gitlab/ci/reports/codequality_reports_comparer_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityReportsComparer do
let(:base_report) { Gitlab::Ci::Reports::CodequalityReports.new }
let(:head_report) { Gitlab::Ci::Reports::CodequalityReports.new }
let(:major_degradation) { build(:codequality_degradation, :major) }
- let(:minor_degradation) { build(:codequality_degradation, :major) }
+ let(:minor_degradation) { build(:codequality_degradation, :minor) }
let(:critical_degradation) { build(:codequality_degradation, :critical) }
let(:blocker_degradation) { build(:codequality_degradation, :blocker) }
diff --git a/spec/lib/gitlab/ci/reports/test_failure_history_spec.rb b/spec/lib/gitlab/ci/reports/test_failure_history_spec.rb
index 9ee55177ca0..21216241cfb 100644
--- a/spec/lib/gitlab/ci/reports/test_failure_history_spec.rb
+++ b/spec/lib/gitlab/ci/reports/test_failure_history_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe Gitlab::Ci::Reports::TestFailureHistory, :aggregate_failures do
describe '#load!' do
let_it_be(:project) { create(:project) }
+
let(:failed_rspec) { create_test_case_rspec_failed }
let(:failed_java) { create_test_case_java_failed }
diff --git a/spec/lib/gitlab/ci/status/core_spec.rb b/spec/lib/gitlab/ci/status/core_spec.rb
new file mode 100644
index 00000000000..b68e4f03433
--- /dev/null
+++ b/spec/lib/gitlab/ci/status/core_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe Gitlab::Ci::Status::Core do
+ let(:subj) { double("subject", cache_key: "foo") }
+
+ subject(:status) do
+ described_class.new(subj, double("user"))
+ end
+
+ describe "#cache_key" do
+ it "uses the subject's cache key" do
+ expect(status.cache_key).to eq(subj.cache_key)
+ end
+ end
+end
diff --git a/spec/lib/gitlab/ci/syntax_templates_spec.rb b/spec/lib/gitlab/ci/syntax_templates_spec.rb
deleted file mode 100644
index ce3169e17ec..00000000000
--- a/spec/lib/gitlab/ci/syntax_templates_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe 'ci/syntax_templates' do
- let_it_be(:project) { create(:project, :repository) }
- let_it_be(:user) { create(:user) }
- let(:lint) { Gitlab::Ci::Lint.new(project: project, current_user: user) }
-
- before do
- project.add_developer(user)
- end
-
- subject(:lint_result) { lint.validate(content) }
-
- Dir.glob('lib/gitlab/ci/syntax_templates/**/*.yml').each do |template|
- describe template do
- let(:content) { File.read(template) }
-
- it 'validates the template' do
- expect(lint_result).to be_valid, "got errors: #{lint_result.errors.join(', ')}"
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/ci/templates/Jobs/build_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Jobs/build_gitlab_ci_yaml_spec.rb
index 1f278048ad5..053499344e1 100644
--- a/spec/lib/gitlab/ci/templates/Jobs/build_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Jobs/build_gitlab_ci_yaml_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe 'Jobs/Build.gitlab-ci.yml' do
end
context 'on merge request' do
- let(:service) { MergeRequests::CreatePipelineService.new(project, user) }
+ let(:service) { MergeRequests::CreatePipelineService.new(project: project, current_user: user) }
let(:merge_request) { create(:merge_request, :simple, source_project: project) }
let(:pipeline) { service.execute(merge_request) }
diff --git a/spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb
index 0a76de82421..b23457315cc 100644
--- a/spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe 'Jobs/Code-Quality.gitlab-ci.yml' do
end
context 'on merge request' do
- let(:service) { MergeRequests::CreatePipelineService.new(project, user) }
+ let(:service) { MergeRequests::CreatePipelineService.new(project: project, current_user: user) }
let(:merge_request) { create(:merge_request, :simple, source_project: project) }
let(:pipeline) { service.execute(merge_request) }
diff --git a/spec/lib/gitlab/ci/templates/Jobs/deploy_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Jobs/deploy_gitlab_ci_yaml_spec.rb
index 25c88c161ea..1d137ef89e1 100644
--- a/spec/lib/gitlab/ci/templates/Jobs/deploy_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Jobs/deploy_gitlab_ci_yaml_spec.rb
@@ -208,7 +208,7 @@ RSpec.describe 'Jobs/Deploy.gitlab-ci.yml' do
end
context 'on merge request' do
- let(:service) { MergeRequests::CreatePipelineService.new(project, user) }
+ let(:service) { MergeRequests::CreatePipelineService.new(project: project, current_user: user) }
let(:merge_request) { create(:merge_request, :simple, source_project: project) }
let(:pipeline) { service.execute(merge_request) }
diff --git a/spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb
index b64959a9917..7fa8d906d07 100644
--- a/spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe 'Jobs/Test.gitlab-ci.yml' do
end
context 'on merge request' do
- let(:service) { MergeRequests::CreatePipelineService.new(project, user) }
+ let(:service) { MergeRequests::CreatePipelineService.new(project: project, current_user: user) }
let(:merge_request) { create(:merge_request, :simple, source_project: project) }
let(:pipeline) { service.execute(merge_request) }
diff --git a/spec/lib/gitlab/ci/templates/Verify/load_performance_testing_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Verify/load_performance_testing_gitlab_ci_yaml_spec.rb
index 03fa45fe0a1..e53d2f4f975 100644
--- a/spec/lib/gitlab/ci/templates/Verify/load_performance_testing_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Verify/load_performance_testing_gitlab_ci_yaml_spec.rb
@@ -62,7 +62,7 @@ RSpec.describe 'Verify/Load-Performance-Testing.gitlab-ci.yml' do
end
context 'on merge request' do
- let(:service) { MergeRequests::CreatePipelineService.new(project, user) }
+ let(:service) { MergeRequests::CreatePipelineService.new(project: project, current_user: user) }
let(:merge_request) { create(:merge_request, :simple, source_project: project) }
let(:pipeline) { service.execute(merge_request) }
diff --git a/spec/lib/gitlab/ci/templates/templates_spec.rb b/spec/lib/gitlab/ci/templates/templates_spec.rb
index 768256ee6b3..56443e611e8 100644
--- a/spec/lib/gitlab/ci/templates/templates_spec.rb
+++ b/spec/lib/gitlab/ci/templates/templates_spec.rb
@@ -22,14 +22,34 @@ RSpec.describe 'CI YML Templates' do
with_them do
let(:content) do
- <<~EOS
- include:
- - template: #{template_name}
+ if template_name == 'Security/DAST-API.gitlab-ci.yml'
+ # The DAST-API template purposly excludes a stages
+ # definition.
- concrete_build_implemented_by_a_user:
- stage: test
- script: do something
- EOS
+ <<~EOS
+ include:
+ - template: #{template_name}
+
+ stages:
+ - build
+ - test
+ - deploy
+ - dast
+
+ concrete_build_implemented_by_a_user:
+ stage: test
+ script: do something
+ EOS
+ else
+ <<~EOS
+ include:
+ - template: #{template_name}
+
+ concrete_build_implemented_by_a_user:
+ stage: test
+ script: do something
+ EOS
+ end
end
it 'is valid' do
diff --git a/spec/lib/gitlab/ci/trace/chunked_io_spec.rb b/spec/lib/gitlab/ci/trace/chunked_io_spec.rb
index f09e03b4d55..f878d24fe4b 100644
--- a/spec/lib/gitlab/ci/trace/chunked_io_spec.rb
+++ b/spec/lib/gitlab/ci/trace/chunked_io_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
include ChunkedIOHelpers
let_it_be(:build) { create(:ci_build, :running) }
+
let(:chunked_io) { described_class.new(build) }
before do
diff --git a/spec/lib/gitlab/ci/trace_spec.rb b/spec/lib/gitlab/ci/trace_spec.rb
index 0fe7c731f27..69f56871740 100644
--- a/spec/lib/gitlab/ci/trace_spec.rb
+++ b/spec/lib/gitlab/ci/trace_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Trace, :clean_gitlab_redis_shared_state, factory_default: :keep do
let_it_be(:project) { create_default(:project).freeze }
let_it_be_with_reload(:build) { create(:ci_build, :success) }
+
let(:trace) { described_class.new(build) }
describe "associations" do
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index ad94dfc9160..94ab4819361 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -1419,155 +1419,6 @@ module Gitlab
end
end
- context 'with multiple_cache_per_job FF disabled' do
- before do
- stub_feature_flags(multiple_cache_per_job: false)
- end
- describe 'cache' do
- context 'when cache definition has unknown keys' do
- let(:config) do
- YAML.dump(
- { cache: { untracked: true, invalid: 'key' },
- rspec: { script: 'rspec' } })
- end
-
- it_behaves_like 'returns errors', 'cache config contains unknown keys: invalid'
- end
-
- it "returns cache when defined globally" do
- config = YAML.dump({
- cache: { paths: ["logs/", "binaries/"], untracked: true, key: 'key' },
- rspec: {
- script: "rspec"
- }
- })
-
- config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
-
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first[:cache]).to eq(
- paths: ["logs/", "binaries/"],
- untracked: true,
- key: 'key',
- policy: 'pull-push',
- when: 'on_success'
- )
- end
-
- it "returns cache when defined in default context" do
- config = YAML.dump(
- {
- default: {
- cache: { paths: ["logs/", "binaries/"], untracked: true, key: { files: ['file'] } }
- },
- rspec: {
- script: "rspec"
- }
- })
-
- config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
-
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first[:cache]).to eq(
- paths: ["logs/", "binaries/"],
- untracked: true,
- key: { files: ['file'] },
- policy: 'pull-push',
- when: 'on_success'
- )
- end
-
- it 'returns cache key when defined in a job' do
- config = YAML.dump({
- rspec: {
- cache: { paths: ['logs/', 'binaries/'], untracked: true, key: 'key' },
- script: 'rspec'
- }
- })
-
- config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
-
- expect(config_processor.stage_builds_attributes('test').size).to eq(1)
- expect(config_processor.stage_builds_attributes('test').first[:cache]).to eq(
- paths: ['logs/', 'binaries/'],
- untracked: true,
- key: 'key',
- policy: 'pull-push',
- when: 'on_success'
- )
- end
-
- it 'returns cache files' do
- config = YAML.dump(
- rspec: {
- cache: {
- paths: ['logs/', 'binaries/'],
- untracked: true,
- key: { files: ['file'] }
- },
- script: 'rspec'
- }
- )
-
- config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
-
- expect(config_processor.stage_builds_attributes('test').size).to eq(1)
- expect(config_processor.stage_builds_attributes('test').first[:cache]).to eq(
- paths: ['logs/', 'binaries/'],
- untracked: true,
- key: { files: ['file'] },
- policy: 'pull-push',
- when: 'on_success'
- )
- end
-
- it 'returns cache files with prefix' do
- config = YAML.dump(
- rspec: {
- cache: {
- paths: ['logs/', 'binaries/'],
- untracked: true,
- key: { files: ['file'], prefix: 'prefix' }
- },
- script: 'rspec'
- }
- )
-
- config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
-
- expect(config_processor.stage_builds_attributes('test').size).to eq(1)
- expect(config_processor.stage_builds_attributes('test').first[:cache]).to eq(
- paths: ['logs/', 'binaries/'],
- untracked: true,
- key: { files: ['file'], prefix: 'prefix' },
- policy: 'pull-push',
- when: 'on_success'
- )
- end
-
- it "overwrite cache when defined for a job and globally" do
- config = YAML.dump({
- cache: { paths: ["logs/", "binaries/"], untracked: true, key: 'global' },
- rspec: {
- script: "rspec",
- cache: { paths: ["test/"], untracked: false, key: 'local' }
- }
- })
-
- config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
-
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first[:cache]).to eq(
- paths: ["test/"],
- untracked: false,
- key: 'local',
- policy: 'pull-push',
- when: 'on_success'
- )
- end
- end
- end
-
describe 'cache' do
context 'when cache definition has unknown keys' do
let(:config) do