Commit 5d0537bb authored by Matija Čupić's avatar Matija Čupić

Check for artifact locking in artifact_*? methods

parent 8a13ab76
......@@ -777,6 +777,8 @@ module Ci
end
def artifacts_expired?
return false if artifacts_locked?
artifacts_expire_at && artifacts_expire_at < Time.current
end
......@@ -958,6 +960,10 @@ module Ci
private
def artifacts_locked?
job_artifacts_archive&.locked?
end
def dependencies
strong_memoize(:dependencies) do
Ci::BuildDependencies.new(self)
......@@ -1027,6 +1033,8 @@ module Ci
end
def has_expiring_artifacts?
return false if artifacts_locked?
artifacts_expire_at.present? && artifacts_expire_at > Time.current
end
......
......@@ -590,22 +590,28 @@ describe Ci::Build do
describe '#artifacts?' do
subject { build.artifacts? }
context 'when new artifacts are used' do
context 'artifacts archive does not exist' do
let(:build) { create(:ci_build) }
context 'artifacts archive does not exist' do
let(:build) { create(:ci_build) }
it { is_expected.to be_falsy }
end
it { is_expected.to be_falsy }
end
context 'artifacts archive exists' do
let(:build) { create(:ci_build, :artifacts) }
context 'artifacts archive exists' do
let(:build) { create(:ci_build, :artifacts) }
it { is_expected.to be_truthy }
it { is_expected.to be_truthy }
context 'is expired' do
let(:build) { create(:ci_build, :artifacts, :expired) }
it { is_expected.to be_falsy }
context 'is expired' do
let(:build) { create(:ci_build, :artifacts, :expired) }
context 'is locked' do
before do
build.job_artifacts_archive.update(locked: true)
end
it { is_expected.to be_falsy }
it { is_expected.to be_truthy }
end
end
end
......@@ -630,6 +636,14 @@ describe Ci::Build do
end
it { is_expected.to be_truthy }
context 'is locked' do
before do
create(:ci_job_artifact, :archive, job: build, locked: true)
end
it { is_expected.to be_falsey }
end
end
context 'is not expired' do
......@@ -2252,6 +2266,16 @@ describe Ci::Build do
it 'has expiring artifacts' do
expect(build).to have_expiring_archive_artifacts
end
context 'and job artifacts are locked' do
before do
archive.update(locked: true)
end
it 'does not have expiring artifacts' do
expect(build).not_to have_expiring_archive_artifacts
end
end
end
context 'and job artifacts archive record does not exist' do
......
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