Welcome to mirror list, hosted at ThFree Co, Russian Federation.

purge_dependency_proxy_cache_worker_spec.rb « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d8be6cdd1a11c97c4dafa53cbe07d4d0891b956b (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe PurgeDependencyProxyCacheWorker, feature_category: :dependency_proxy do
  let_it_be(:user) { create(:admin) }
  let_it_be_with_refind(:blob) { create(:dependency_proxy_blob ) }
  let_it_be_with_reload(:group) { blob.group }
  let_it_be_with_refind(:manifest) { create(:dependency_proxy_manifest, group: group ) }
  let_it_be(:group_id) { group.id }

  subject { described_class.new.perform(user.id, group_id) }

  describe '#perform' do
    shared_examples 'not expiring blobs and manifests' do
      it 'does not expire blobs and manifests', :aggregate_failures do
        expect { subject }.not_to change { blob.status }
        expect { subject }.not_to change { manifest.status }
        expect(subject).to be_nil
      end
    end

    context 'an admin user' do
      context 'when admin mode is enabled', :enable_admin_mode do
        it_behaves_like 'an idempotent worker' do
          let(:job_args) { [user.id, group_id] }

          it 'marks the blobs as pending_destruction and returns ok', :aggregate_failures do
            subject

            expect(blob).to be_pending_destruction
            expect(manifest).to be_pending_destruction
          end
        end
      end

      context 'when admin mode is disabled' do
        it_behaves_like 'not expiring blobs and manifests'
      end
    end

    context 'a non-admin user' do
      let(:user) { create(:user) }

      it_behaves_like 'not expiring blobs and manifests'
    end

    context 'an invalid user id' do
      let(:user) { double('User', id: 99999 ) }

      it_behaves_like 'not expiring blobs and manifests'
    end

    context 'an invalid group' do
      let(:group_id) { 99999 }

      it_behaves_like 'not expiring blobs and manifests'
    end
  end
end