BigW Consortium Gitlab

expire_build_instance_artifacts_worker_spec.rb 1.99 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

describe ExpireBuildInstanceArtifactsWorker do
  include RepoHelpers

  let(:worker) { described_class.new }

  describe '#perform' do
9 10 11
    before do
      worker.perform(build.id)
    end
12 13

    context 'with expired artifacts' do
14
      let(:artifacts_expiry) { { artifacts_expire_at: Time.now - 7.days } }
15

16 17 18 19 20 21 22 23
      context 'when associated project is valid' do
        let(:build) do
          create(:ci_build, :artifacts, artifacts_expiry)
        end

        it 'does expire' do
          expect(build.reload.artifacts_expired?).to be_truthy
        end
24

25 26 27 28 29 30 31
        it 'does remove files' do
          expect(build.reload.artifacts_file.exists?).to be_falsey
        end

        it 'does nullify artifacts_file column' do
          expect(build.reload.artifacts_file_identifier).to be_nil
        end
32 33 34 35
      end
    end

    context 'with not yet expired artifacts' do
36 37 38
      let(:build) do
        create(:ci_build, :artifacts, artifacts_expire_at: Time.now + 7.days)
      end
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

      it 'does not expire' do
        expect(build.reload.artifacts_expired?).to be_falsey
      end

      it 'does not remove files' do
        expect(build.reload.artifacts_file.exists?).to be_truthy
      end

      it 'does not nullify artifacts_file column' do
        expect(build.reload.artifacts_file_identifier).not_to be_nil
      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
        expect(build.reload.artifacts_file.exists?).to be_truthy
      end

      it 'does not nullify artifacts_file column' do
        expect(build.reload.artifacts_file_identifier).not_to be_nil
      end
    end

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

      it 'is still expired' do
        expect(build.reload.artifacts_expired?).to be_truthy
      end
    end
  end
end