2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::ContainerRepository::DestroyService do
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :private) }
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
subject { described_class.new(project, user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have access to registry' do
|
|
|
|
let!(:repository) { create(:container_repository, :root, project: project) }
|
|
|
|
|
|
|
|
it 'does not delete a repository' do
|
|
|
|
expect { subject.execute(repository) }.not_to change { ContainerRepository.all.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has access to registry' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when root container repository exists' do
|
|
|
|
let!(:repository) { create(:container_repository, :root, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: :any, tags: [])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes the repository' do
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(repository).to receive(:delete_tags!).and_call_original
|
2018-11-20 20:47:30 +05:30
|
|
|
expect { described_class.new(project, user).execute(repository) }.to change { ContainerRepository.all.count }.by(-1)
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
context 'when destroy fails' do
|
|
|
|
it 'set delete_status' do
|
|
|
|
allow(repository).to receive(:destroy).and_return(false)
|
|
|
|
|
|
|
|
subject.execute(repository)
|
|
|
|
|
|
|
|
expect(repository).to be_delete_failed
|
|
|
|
end
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|