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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-10-05 20:33:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-10-05 20:33:30 +0300
commit5049b3cd2362d119d0f6147bb45b449609b07cb4 (patch)
tree69c89f0b19c09d3600ab3772be20209d4d702d36 /spec
parentd5cc1255b64367c04f208150dbafa0be7b50dc45 (diff)
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec')
-rw-r--r--spec/services/projects/container_repository/cleanup_tags_service_spec.rb6
-rw-r--r--spec/services/projects/container_repository/delete_tags_service_spec.rb120
2 files changed, 72 insertions, 54 deletions
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