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
|
|
|
|
2016-10-07 09:11:02 +00:00
|
|
|
before { Sidekiq::Worker.clear_all }
|
|
|
|
|
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-10-07 09:11:02 +00:00
|
|
|
subject! do
|
|
|
|
Sidekiq::Testing.fake! { worker.perform }
|
|
|
|
end
|
2016-06-10 19:45:06 +00:00
|
|
|
|
2016-06-13 14:05:23 +00:00
|
|
|
context 'with expired artifacts' do
|
2016-06-14 09:38:34 +00:00
|
|
|
let(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now - 7.days) }
|
2016-06-10 19:45:06 +00:00
|
|
|
|
2016-10-07 09:11:02 +00:00
|
|
|
it 'enqueues that build' do
|
|
|
|
expect(jobs_enqueued.size).to eq(1)
|
|
|
|
expect(jobs_enqueued[0]["args"]).to eq([build.id])
|
2016-06-17 10:58:26 +00:00
|
|
|
end
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with not yet expired artifacts' do
|
2016-06-14 09:38:34 +00:00
|
|
|
let(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now + 7.days) }
|
2016-06-10 15:27:49 +00:00
|
|
|
|
2016-10-07 09:11:02 +00:00
|
|
|
it 'does not enqueue that build' do
|
|
|
|
expect(jobs_enqueued.size).to eq(0)
|
2016-06-17 10:58:26 +00:00
|
|
|
end
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'without expire date' do
|
2016-06-14 09:38:34 +00:00
|
|
|
let(:build) { create(:ci_build, :artifacts) }
|
2016-06-10 15:27:49 +00:00
|
|
|
|
2016-10-07 09:11:02 +00:00
|
|
|
it 'does not enqueue that build' do
|
|
|
|
expect(jobs_enqueued.size).to eq(0)
|
2016-06-17 10:58:26 +00:00
|
|
|
end
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
|
2016-10-07 09:11:02 +00:00
|
|
|
def jobs_enqueued
|
|
|
|
Sidekiq::Queues.jobs_by_worker['ExpireBuildInstanceArtifactsWorker']
|
2016-06-10 15:27:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|