2016-06-10 15:27:49 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ExpireBuildArtifactsWorker do
|
|
|
|
include RepoHelpers
|
|
|
|
|
2016-06-10 19:45:06 +00:00
|
|
|
let(:worker) { described_class.new }
|
2016-06-10 15:27:49 +00:00
|
|
|
|
|
|
|
describe '#perform' do
|
2016-06-13 14:05:23 +00:00
|
|
|
before { build }
|
2016-06-10 15:27:49 +00:00
|
|
|
|
2016-06-13 14:05:23 +00:00
|
|
|
subject! { worker.perform }
|
2016-06-10 19:45:06 +00:00
|
|
|
|
2016-06-13 14:05:23 +00:00
|
|
|
context 'with expired artifacts' do
|
|
|
|
let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now - 7.days) }
|
2016-06-10 19:45:06 +00:00
|
|
|
|
2016-06-13 14:05:23 +00:00
|
|
|
it 'does expire' do
|
2016-06-10 19:45:06 +00:00
|
|
|
expect(build.reload.artifacts_expired?).to be_truthy
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with not yet expired artifacts' do
|
|
|
|
let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now + 7.days) }
|
|
|
|
|
2016-06-13 14:05:23 +00:00
|
|
|
it 'does not expire' do
|
|
|
|
expect(build.reload.artifacts_expired?).to be_truthy
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without expire date' do
|
|
|
|
let!(:build) { create(:ci_build, :artifacts) }
|
|
|
|
|
2016-06-13 14:05:23 +00:00
|
|
|
it 'does not expire' do
|
|
|
|
expect(build.reload.artifacts_expired?).to be_falsey
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for expired artifacts' do
|
|
|
|
let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now - 7.days) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
build.erase_artifacts!
|
2016-06-10 15:31:22 +00:00
|
|
|
build.save
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_any_instance_of(Ci::Build).not_to receive(:erase_artifacts!)
|
2016-06-10 19:45:06 +00:00
|
|
|
|
2016-06-10 15:27:49 +00:00
|
|
|
worker.perform
|
2016-06-10 19:45:06 +00:00
|
|
|
|
|
|
|
expect(build.reload.artifacts_expired?).to be_truthy
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|