Commit 771b9739 authored by Matija Čupić's avatar Matija Čupić

Use Project.cache_index in Build#cache

parent 0a002e23
...@@ -461,8 +461,12 @@ module Ci ...@@ -461,8 +461,12 @@ module Ci
end end
def cache def cache
if options[:cache] && project.cache_index
options[:cache].merge(key: "#{options[:cache][:key]}:#{project.cache_index}")
else
[options[:cache]] [options[:cache]]
end end
end
def credentials def credentials
Gitlab::Ci::Build::Credentials::Factory.new(self).create! Gitlab::Ci::Build::Credentials::Factory.new(self).create!
......
...@@ -255,6 +255,42 @@ describe Ci::Build do ...@@ -255,6 +255,42 @@ describe Ci::Build do
end end
end end
describe '#cache' do
let(:options) { { cache: { key: "key", paths: ["public"], policy: "pull-push" } } }
subject { build.cache }
context 'when build has cache' do
before do
allow(build).to receive(:options).and_return(options)
end
context 'when project has cache_index' do
before do
allow_any_instance_of(Project).to receive(:cache_index).and_return(1)
end
it { is_expected.to include(key: "key:1") }
end
context 'when project does not have cache_index' do
before do
allow_any_instance_of(Project).to receive(:cache_index).and_return(nil)
end
it { is_expected.to eq([options[:cache]]) }
end
end
context 'when build does not have cache' do
before do
allow(build).to receive(:options).and_return({})
end
it { is_expected.to eq([nil]) }
end
end
describe '#depends_on_builds' do describe '#depends_on_builds' do
let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') } let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') }
let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') } let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment