diff options
Diffstat (limited to 'spec/lib/gitlab/ci/build/cache_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/build/cache_spec.rb | 98 |
1 files changed, 29 insertions, 69 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 |