2019-03-02 22:35:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe CleanupContainerRepositoryWorker, :clean_gitlab_redis_shared_state do
|
2019-03-02 22:35:43 +05:30
|
|
|
let(:repository) { create(:container_repository) }
|
|
|
|
let(:project) { repository.project }
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:user) { project.first_owner }
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
let(:service) { instance_double(Projects::ContainerRepository::CleanupTagsService) }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
context 'bulk delete api' do
|
|
|
|
let(:params) { { key: 'value', 'container_expiration_policy' => false } }
|
|
|
|
|
|
|
|
it 'executes the destroy service' do
|
|
|
|
expect(Projects::ContainerRepository::CleanupTagsService).to receive(:new)
|
2021-11-18 22:05:49 +05:30
|
|
|
.with(repository, user, params.merge('container_expiration_policy' => false))
|
2020-03-13 15:44:24 +05:30
|
|
|
.and_return(service)
|
|
|
|
expect(service).to receive(:execute)
|
|
|
|
|
|
|
|
subject.perform(user.id, repository.id, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error when user could not be found' do
|
|
|
|
expect do
|
|
|
|
subject.perform(-1, repository.id, params)
|
|
|
|
end.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error when repository could not be found' do
|
|
|
|
expect do
|
|
|
|
subject.perform(user.id, -1, params)
|
|
|
|
end.not_to raise_error
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
context 'container expiration policy' do
|
|
|
|
let(:params) { { key: 'value', 'container_expiration_policy' => true } }
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
before do
|
|
|
|
allow(ContainerRepository)
|
|
|
|
.to receive(:find_by_id).with(repository.id).and_return(repository)
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'executes the destroy service' do
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(repository).to receive(:start_expiration_policy!).and_call_original
|
|
|
|
expect(repository).to receive(:reset_expiration_policy_started_at!).and_call_original
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(Projects::ContainerRepository::CleanupTagsService).to receive(:new)
|
2021-11-18 22:05:49 +05:30
|
|
|
.with(repository, nil, params.merge('container_expiration_policy' => true))
|
2020-03-13 15:44:24 +05:30
|
|
|
.and_return(service)
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(service).to receive(:execute).and_return(status: :success)
|
|
|
|
|
|
|
|
subject.perform(nil, repository.id, params)
|
|
|
|
expect(repository.reload.expiration_policy_started_at).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't reset the expiration policy started at if the destroy service returns an error" do
|
|
|
|
expect(repository).to receive(:start_expiration_policy!).and_call_original
|
|
|
|
expect(repository).not_to receive(:reset_expiration_policy_started_at!)
|
|
|
|
expect(Projects::ContainerRepository::CleanupTagsService).to receive(:new)
|
2021-11-18 22:05:49 +05:30
|
|
|
.with(repository, nil, params.merge('container_expiration_policy' => true))
|
2021-01-03 14:25:43 +05:30
|
|
|
.and_return(service)
|
|
|
|
|
|
|
|
expect(service).to receive(:execute).and_return(status: :error, message: 'timeout while deleting tags')
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
subject.perform(nil, repository.id, params)
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(repository.reload.expiration_policy_started_at).not_to be_nil
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|