summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-09-05 23:33:30 -0700
committerStan Hu <stanhu@gmail.com>2018-09-07 12:42:59 -0700
commit5830d1143dbf6b2958153233279896961e9a44df (patch)
treec3828d2fb9a5fbd2edc1c0c4a74537c6efe95d8c /spec/services
parent272281e4729c9e2193acea84394a191cfe2496af (diff)
downloadgitlab-ce-5830d1143dbf6b2958153233279896961e9a44df.tar.gz
Delete a container registry asynchronously
When a container registry has many tags, it's easy for the DELETE call to take more than 60 seconds and fail. This can also leave the registry in a bad state with null bytes since some of the images have been deleted with tags still pointing to them. In addition, we have to prevent users from accidentally initiating the delete multiple times or this could leave the registry with orphaned tags. This commit also adds a flash message to notify the user the registry is scheduled for deletion. Closes #49926, #51063
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/projects/container_repository/destroy_service_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/services/projects/container_repository/destroy_service_spec.rb b/spec/services/projects/container_repository/destroy_service_spec.rb
new file mode 100644
index 00000000000..307ccc88865
--- /dev/null
+++ b/spec/services/projects/container_repository/destroy_service_spec.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Projects::ContainerRepository::DestroyService do
+ set(:user) { create(:user) }
+ set(:project) { create(:project, :private) }
+
+ 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
+ expect { described_class.new(project, user).execute(repository) }.to change { ContainerRepository.all.count }.by(-1)
+ end
+ end
+ end
+end