2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe PurgeDependencyProxyCacheWorker do
|
|
|
|
let_it_be(:user) { create(:admin) }
|
|
|
|
let_it_be(:blob) { create(:dependency_proxy_blob )}
|
|
|
|
let_it_be(:group, reload: true) { blob.group }
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:manifest) { create(:dependency_proxy_manifest, group: group )}
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:group_id) { group.id }
|
|
|
|
|
|
|
|
subject { described_class.new.perform(user.id, group_id) }
|
|
|
|
|
|
|
|
describe '#perform' do
|
2021-11-11 11:23:49 +05:30
|
|
|
shared_examples 'not removing blobs and manifests' do
|
|
|
|
it 'does not remove blobs and manifests', :aggregate_failures do
|
2021-01-29 00:20:46 +05:30
|
|
|
expect { subject }.not_to change { group.dependency_proxy_blobs.size }
|
2021-02-22 17:27:13 +05:30
|
|
|
expect { subject }.not_to change { group.dependency_proxy_manifests.size }
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'an admin user' do
|
2021-04-17 20:07:23 +05:30
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
include_examples 'an idempotent worker' do
|
|
|
|
let(:job_args) { [user.id, group_id] }
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'deletes the blobs and returns ok', :aggregate_failures do
|
|
|
|
expect(group.dependency_proxy_blobs.size).to eq(1)
|
|
|
|
expect(group.dependency_proxy_manifests.size).to eq(1)
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
subject
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(group.dependency_proxy_blobs.size).to eq(0)
|
|
|
|
expect(group.dependency_proxy_manifests.size).to eq(0)
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
2021-11-11 11:23:49 +05:30
|
|
|
it_behaves_like 'not removing blobs and manifests'
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'a non-admin user' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it_behaves_like 'not removing blobs and manifests'
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'an invalid user id' do
|
|
|
|
let(:user) { double('User', id: 99999 ) }
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it_behaves_like 'not removing blobs and manifests'
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'an invalid group' do
|
|
|
|
let(:group_id) { 99999 }
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it_behaves_like 'not removing blobs and manifests'
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|