summaryrefslogtreecommitdiff
path: root/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb
blob: 2bdd8345374bc91d3507a51c26f7ea0280f93cb8 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker do
  let(:worker) { described_class.new }

  describe '#perform' do
    let_it_be(:pipeline_artifact) do
      create(:ci_pipeline_artifact, :with_coverage_report, expire_at: 1.week.ago)
    end

    it 'executes a service' do
      expect_next_instance_of(::Ci::PipelineArtifacts::DestroyExpiredArtifactsService) do |instance|
        expect(instance).to receive(:execute)
      end

      worker.perform
    end

    include_examples 'an idempotent worker' do
      subject do
        perform_multiple(worker: worker)
      end

      it 'removes the artifact only once' do
        expect(worker).to receive(:log_extra_metadata_on_done).with(:destroyed_pipeline_artifacts_count, 1)
        expect(worker).to receive(:log_extra_metadata_on_done).with(:destroyed_pipeline_artifacts_count, 0)

        subject

        expect { pipeline_artifact.reload }.to raise_error(ActiveRecord::RecordNotFound)
      end
    end
  end
end