2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-07 09:11:02 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe ExpireBuildInstanceArtifactsWorker do
|
2016-10-07 09:11:02 +00:00
|
|
|
include RepoHelpers
|
|
|
|
|
|
|
|
let(:worker) { described_class.new }
|
|
|
|
|
|
|
|
describe '#perform' do
|
2016-10-14 09:30:06 +00:00
|
|
|
before do
|
|
|
|
worker.perform(build.id)
|
|
|
|
end
|
2016-10-07 09:11:02 +00:00
|
|
|
|
|
|
|
context 'with expired artifacts' do
|
2016-10-14 09:30:06 +00:00
|
|
|
context 'when associated project is valid' do
|
2017-09-21 08:34:12 +00:00
|
|
|
let(:build) { create(:ci_build, :artifacts, :expired) }
|
2016-10-14 09:30:06 +00:00
|
|
|
|
|
|
|
it 'does expire' do
|
|
|
|
expect(build.reload.artifacts_expired?).to be_truthy
|
|
|
|
end
|
2016-10-07 09:11:02 +00:00
|
|
|
|
2016-10-14 09:30:06 +00:00
|
|
|
it 'does remove files' do
|
2019-03-22 12:38:45 +00:00
|
|
|
expect(build.reload.artifacts_file.present?).to be_falsey
|
2016-10-14 09:30:06 +00:00
|
|
|
end
|
|
|
|
|
2017-09-21 08:34:12 +00:00
|
|
|
it 'does remove the job artifact record' do
|
2017-11-30 13:18:38 +00:00
|
|
|
expect(build.reload.job_artifacts_archive).to be_nil
|
2016-10-14 09:30:06 +00:00
|
|
|
end
|
2016-10-07 09:11:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with not yet expired artifacts' do
|
2020-02-25 03:08:49 +00:00
|
|
|
let_it_be(:build) do
|
2020-06-24 06:09:01 +00:00
|
|
|
create(:ci_build, :artifacts, artifacts_expire_at: Time.current + 7.days)
|
2016-10-14 09:30:06 +00:00
|
|
|
end
|
2016-10-07 09:11:02 +00:00
|
|
|
|
|
|
|
it 'does not expire' do
|
|
|
|
expect(build.reload.artifacts_expired?).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not remove files' do
|
2019-03-22 12:38:45 +00:00
|
|
|
expect(build.reload.artifacts_file.present?).to be_truthy
|
2016-10-07 09:11:02 +00:00
|
|
|
end
|
|
|
|
|
2017-09-21 08:34:12 +00:00
|
|
|
it 'does not remove the job artifact record' do
|
2017-11-30 13:18:38 +00:00
|
|
|
expect(build.reload.job_artifacts_archive).not_to be_nil
|
2016-10-07 09:11:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without expire date' do
|
|
|
|
let(:build) { create(:ci_build, :artifacts) }
|
|
|
|
|
|
|
|
it 'does not expire' do
|
|
|
|
expect(build.reload.artifacts_expired?).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not remove files' do
|
2019-03-22 12:38:45 +00:00
|
|
|
expect(build.reload.artifacts_file.present?).to be_truthy
|
2016-10-07 09:11:02 +00:00
|
|
|
end
|
|
|
|
|
2017-09-21 08:34:12 +00:00
|
|
|
it 'does not remove the job artifact record' do
|
2017-11-30 13:18:38 +00:00
|
|
|
expect(build.reload.job_artifacts_archive).not_to be_nil
|
2016-10-07 09:11:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for expired artifacts' do
|
2017-09-21 08:34:12 +00:00
|
|
|
let(:build) { create(:ci_build, :expired) }
|
2016-10-07 09:11:02 +00:00
|
|
|
|
|
|
|
it 'is still expired' do
|
|
|
|
expect(build.reload.artifacts_expired?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|