Use Project.cache_index in Build#cache

This commit is contained in:
Matija Čupić 2017-12-22 23:06:15 +01:00
parent 0a002e230b
commit 771b97394a
No known key found for this signature in database
GPG key ID: 4BAF84FFACD2E5DE
2 changed files with 41 additions and 1 deletions

View file

@ -461,7 +461,11 @@ module Ci
end
def cache
[options[:cache]]
if options[:cache] && project.cache_index
options[:cache].merge(key: "#{options[:cache][:key]}:#{project.cache_index}")
else
[options[:cache]]
end
end
def credentials

View file

@ -255,6 +255,42 @@ describe Ci::Build do
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
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') }