From 5049b3cd2362d119d0f6147bb45b449609b07cb4 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 5 Oct 2020 17:33:30 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-4-stable-ee --- .../cleanup_tags_service_spec.rb | 6 +- .../delete_tags_service_spec.rb | 120 ++++++++++++--------- 2 files changed, 72 insertions(+), 54 deletions(-) (limited to 'spec') diff --git a/spec/services/projects/container_repository/cleanup_tags_service_spec.rb b/spec/services/projects/container_repository/cleanup_tags_service_spec.rb index 2c708e75a25..2f2474f2681 100644 --- a/spec/services/projects/container_repository/cleanup_tags_service_spec.rb +++ b/spec/services/projects/container_repository/cleanup_tags_service_spec.rb @@ -245,7 +245,7 @@ RSpec.describe Projects::ContainerRepository::CleanupTagsService do end it 'succeeds without a user' do - expect_delete(%w(Bb Ba C)) + expect_delete(%w(Bb Ba C), container_expiration_policy: true) is_expected.to include(status: :success, deleted: %w(Bb Ba C)) end @@ -287,10 +287,10 @@ RSpec.describe Projects::ContainerRepository::CleanupTagsService do end end - def expect_delete(tags) + def expect_delete(tags, container_expiration_policy: nil) expect(Projects::ContainerRepository::DeleteTagsService) .to receive(:new) - .with(repository.project, user, tags: tags) + .with(repository.project, user, tags: tags, container_expiration_policy: container_expiration_policy) .and_call_original expect_any_instance_of(Projects::ContainerRepository::DeleteTagsService) 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 -- cgit v1.2.3