summaryrefslogtreecommitdiff
path: root/spec/workers/expire_build_artifacts_worker_spec.rb
blob: 73cbadc13d910399296a52bbed999525815f7caf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'spec_helper'

describe ExpireBuildArtifactsWorker do
  include RepoHelpers

  let(:worker) { described_class.new }

  before { Sidekiq::Worker.clear_all }

  describe '#perform' do
    before { build }

    subject! do
      Sidekiq::Testing.fake! { worker.perform }
    end

    context 'with expired artifacts' do
      let(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now - 7.days) }

      it 'enqueues that build' do
        expect(jobs_enqueued.size).to eq(1)
        expect(jobs_enqueued[0]["args"]).to eq([build.id])
      end
    end

    context 'with not yet expired artifacts' do
      let(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now + 7.days) }

      it 'does not enqueue that build' do
        expect(jobs_enqueued.size).to eq(0)
      end
    end

    context 'without expire date' do
      let(:build) { create(:ci_build, :artifacts) }

      it 'does not enqueue that build' do
        expect(jobs_enqueued.size).to eq(0)
      end
    end

    def jobs_enqueued
      Sidekiq::Queues.jobs_by_worker['ExpireBuildInstanceArtifactsWorker']
    end
  end
end