diff options
Diffstat (limited to 'spec/lib/gitlab/ci/yaml_processor_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 263 |
1 files changed, 213 insertions, 50 deletions
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 9498453852a..5462a587d16 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -1368,6 +1368,155 @@ 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 @@ -1381,22 +1530,22 @@ module Gitlab it "returns cache when defined globally" do config = YAML.dump({ - cache: { paths: ["logs/", "binaries/"], untracked: true, key: 'key' }, - rspec: { - script: "rspec" - } - }) + 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( + 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 @@ -1413,32 +1562,46 @@ module Gitlab 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( + 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 + it 'returns cache key/s when defined in a job' do config = YAML.dump({ - rspec: { - cache: { paths: ['logs/', 'binaries/'], untracked: true, key: 'key' }, - script: 'rspec' - } - }) + rspec: { + cache: [ + { paths: ['binaries/'], untracked: true, key: 'keya' }, + { 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' + [ + { + paths: ['binaries/'], + untracked: true, + key: 'keya', + policy: 'pull-push', + when: 'on_success' + }, + { + paths: ['logs/', 'binaries/'], + untracked: true, + key: 'key', + policy: 'pull-push', + when: 'on_success' + } + ] ) end @@ -1446,10 +1609,10 @@ module Gitlab config = YAML.dump( rspec: { cache: { - paths: ['logs/', 'binaries/'], - untracked: true, - key: { files: ['file'] } - }, + paths: ['binaries/'], + untracked: true, + key: { files: ['file'] } + }, script: 'rspec' } ) @@ -1457,13 +1620,13 @@ module Gitlab 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/'], + expect(config_processor.stage_builds_attributes('test').first[:cache]).to eq([ + paths: ['binaries/'], untracked: true, key: { files: ['file'] }, policy: 'pull-push', when: 'on_success' - ) + ]) end it 'returns cache files with prefix' do @@ -1481,34 +1644,34 @@ module Gitlab 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( + 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' } - } - }) + 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( + 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 @@ -1926,8 +2089,8 @@ module Gitlab only: { refs: %w[branches tags] }, options: { script: ["test"] }, needs_attributes: [ - { name: "build1", artifacts: true }, - { name: "build2", artifacts: true } + { name: "build1", artifacts: true, optional: false }, + { name: "build2", artifacts: true, optional: false } ], when: "on_success", allow_failure: false, @@ -1941,7 +2104,7 @@ module Gitlab let(:needs) do [ { job: 'parallel', artifacts: false }, - { job: 'build1', artifacts: true }, + { job: 'build1', artifacts: true, optional: true }, 'build2' ] end @@ -1968,10 +2131,10 @@ module Gitlab only: { refs: %w[branches tags] }, options: { script: ["test"] }, needs_attributes: [ - { name: "parallel 1/2", artifacts: false }, - { name: "parallel 2/2", artifacts: false }, - { name: "build1", artifacts: true }, - { name: "build2", artifacts: true } + { name: "parallel 1/2", artifacts: false, optional: false }, + { name: "parallel 2/2", artifacts: false, optional: false }, + { name: "build1", artifacts: true, optional: true }, + { name: "build2", artifacts: true, optional: false } ], when: "on_success", allow_failure: false, @@ -1993,8 +2156,8 @@ module Gitlab only: { refs: %w[branches tags] }, options: { script: ["test"] }, needs_attributes: [ - { name: "parallel 1/2", artifacts: true }, - { name: "parallel 2/2", artifacts: true } + { name: "parallel 1/2", artifacts: true, optional: false }, + { name: "parallel 2/2", artifacts: true, optional: false } ], when: "on_success", allow_failure: false, @@ -2022,10 +2185,10 @@ module Gitlab only: { refs: %w[branches tags] }, options: { script: ["test"] }, needs_attributes: [ - { name: "build1", artifacts: true }, - { name: "build2", artifacts: true }, - { name: "parallel 1/2", artifacts: true }, - { name: "parallel 2/2", artifacts: true } + { name: "build1", artifacts: true, optional: false }, + { name: "build2", artifacts: true, optional: false }, + { name: "parallel 1/2", artifacts: true, optional: false }, + { name: "parallel 2/2", artifacts: true, optional: false } ], when: "on_success", allow_failure: false, |