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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/projects/container_repository/delete_tags_service_spec.rb')
-rw-r--r--spec/services/projects/container_repository/delete_tags_service_spec.rb120
1 files changed, 69 insertions, 51 deletions
diff --git a/spec/services/projects/container_repository/delete_tags_service_spec.rb b/spec/services/projects/container_repository/delete_tags_service_spec.rb
index 5116427dad2..54375193067 100644
--- a/spec/services/projects/container_repository/delete_tags_service_spec.rb
+++ b/spec/services/projects/container_repository/delete_tags_service_spec.rb
@@ -85,81 +85,85 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
end
end
- describe '#execute' do
- let(:tags) { %w[A Ba] }
-
- subject { service.execute(repository) }
-
- before do
- stub_feature_flags(container_registry_expiration_policies_throttling: false)
- end
+ RSpec.shared_examples 'supporting fast delete' do
+ context 'when the registry supports fast delete' do
+ context 'and the feature is enabled' do
+ before do
+ allow(repository.client).to receive(:supports_tag_delete?).and_return(true)
+ end
- context 'without permissions' do
- it { is_expected.to include(status: :error) }
- end
+ it_behaves_like 'calling the correct delete tags service', ::Projects::ContainerRepository::Gitlab::DeleteTagsService
- context 'with permissions' do
- before do
- project.add_developer(user)
- end
+ it_behaves_like 'handling invalid params'
- context 'when the registry supports fast delete' do
- context 'and the feature is enabled' do
+ context 'with the real service' do
before do
- allow(repository.client).to receive(:supports_tag_delete?).and_return(true)
+ stub_delete_reference_requests(tags)
+ expect_delete_tag_by_names(tags)
end
- it_behaves_like 'calling the correct delete tags service', ::Projects::ContainerRepository::Gitlab::DeleteTagsService
+ it { is_expected.to include(status: :success) }
- it_behaves_like 'handling invalid params'
+ it_behaves_like 'logging a success response'
+ end
- context 'with the real service' do
- before do
- stub_delete_reference_requests(tags)
- expect_delete_tag_by_names(tags)
+ context 'with a timeout error' do
+ before do
+ expect_next_instance_of(::Projects::ContainerRepository::Gitlab::DeleteTagsService) do |delete_service|
+ expect(delete_service).to receive(:delete_tags).and_raise(::Projects::ContainerRepository::Gitlab::DeleteTagsService::TimeoutError)
end
-
- it { is_expected.to include(status: :success) }
-
- it_behaves_like 'logging a success response'
end
- context 'with a timeout error' do
- before do
- expect_next_instance_of(::Projects::ContainerRepository::Gitlab::DeleteTagsService) do |delete_service|
- expect(delete_service).to receive(:delete_tags).and_raise(::Projects::ContainerRepository::Gitlab::DeleteTagsService::TimeoutError)
- end
- end
+ it { is_expected.to include(status: :error, message: 'timeout while deleting tags') }
- it { is_expected.to include(status: :error, message: 'timeout while deleting tags') }
+ it_behaves_like 'logging an error response', message: 'timeout while deleting tags'
+ end
+ end
- it_behaves_like 'logging an error response', message: 'timeout while deleting tags'
- end
+ context 'and the feature is disabled' do
+ before do
+ stub_feature_flags(container_registry_fast_tag_delete: false)
end
- context 'and the feature is disabled' do
+ it_behaves_like 'calling the correct delete tags service', ::Projects::ContainerRepository::ThirdParty::DeleteTagsService
+
+ it_behaves_like 'handling invalid params'
+
+ context 'with the real service' do
before do
- stub_feature_flags(container_registry_fast_tag_delete: false)
+ stub_upload('sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3')
+ tags.each { |tag| stub_put_manifest_request(tag) }
+ expect_delete_tag_by_digest('sha256:dummy')
end
- it_behaves_like 'calling the correct delete tags service', ::Projects::ContainerRepository::ThirdParty::DeleteTagsService
+ it { is_expected.to include(status: :success) }
- it_behaves_like 'handling invalid params'
+ it_behaves_like 'logging a success response'
+ end
+ end
+ end
+ end
- context 'with the real service' do
- before do
- stub_upload('sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3')
- tags.each { |tag| stub_put_manifest_request(tag) }
- expect_delete_tag_by_digest('sha256:dummy')
- end
+ describe '#execute' do
+ let(:tags) { %w[A Ba] }
- it { is_expected.to include(status: :success) }
+ subject { service.execute(repository) }
- it_behaves_like 'logging a success response'
- end
- end
+ before do
+ stub_feature_flags(container_registry_expiration_policies_throttling: false)
+ end
+
+ context 'without permissions' do
+ it { is_expected.to include(status: :error) }
+ end
+
+ context 'with permissions' do
+ before do
+ project.add_developer(user)
end
+ it_behaves_like 'supporting fast delete'
+
context 'when the registry does not support fast delete' do
before do
allow(repository.client).to receive(:supports_tag_delete?).and_return(false)
@@ -170,5 +174,19 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
it_behaves_like 'handling invalid params'
end
end
+
+ context 'without user' do
+ let_it_be(:user) { nil }
+
+ context 'when not run by a cleanup policy' do
+ it { is_expected.to include(status: :error) }
+ end
+
+ context 'when run by a cleanup policy' do
+ let(:params) { { tags: tags, container_expiration_policy: true } }
+
+ it_behaves_like 'supporting fast delete'
+ end
+ end
end
end