diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb')
-rw-r--r-- | spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb b/spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb new file mode 100644 index 00000000000..bcc98cf6416 --- /dev/null +++ b/spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +RSpec.shared_context 'container repository delete tags service shared context' do + let_it_be(:user) { create(:user) } + let_it_be(:project, reload: true) { create(:project, :private) } + let_it_be(:repository) { create(:container_repository, :root, project: project) } + + let(:params) { { tags: tags } } + + before do + stub_container_registry_config(enabled: true, + api_url: 'http://registry.gitlab', + host_port: 'registry.gitlab') + + stub_container_registry_tags( + repository: repository.path, + tags: %w(latest A Ba Bb C D E)) + end + + def stub_delete_reference_request(tag, status = 200) + stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/#{tag}") + .to_return(status: status, body: '') + end + + def stub_delete_reference_requests(tags) + tags = Hash[Array.wrap(tags).map { |tag| [tag, 200] }] unless tags.is_a?(Hash) + + tags.each do |tag, status| + stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/#{tag}") + .to_return(status: status, body: '') + end + end + + def stub_put_manifest_request(tag, status = 200, headers = { 'docker-content-digest' => 'sha256:dummy' }) + stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/#{tag}") + .to_return(status: status, body: '', headers: headers) + end + + def stub_tag_digest(tag, digest) + stub_request(:head, "http://registry.gitlab/v2/#{repository.path}/manifests/#{tag}") + .to_return(status: 200, body: '', headers: { 'docker-content-digest' => digest }) + end + + def stub_digest_config(digest, created_at) + allow_any_instance_of(ContainerRegistry::Client) + .to receive(:blob) + .with(repository.path, digest, nil) do + { 'created' => created_at.to_datetime.rfc3339 }.to_json if created_at + end + end + + def stub_upload(digest, success: true) + content = "{\n \"config\": {\n }\n}" + expect_any_instance_of(ContainerRegistry::Client) + .to receive(:upload_blob) + .with(repository.path, content, digest) { double(success?: success ) } + end + + def expect_delete_tag_by_digest(digest) + expect_any_instance_of(ContainerRegistry::Client) + .to receive(:delete_repository_tag_by_digest) + .with(repository.path, digest) { true } + + expect_any_instance_of(ContainerRegistry::Client) + .not_to receive(:delete_repository_tag_by_name) + end + + def expect_delete_tag_by_names(names) + Array.wrap(names).each do |name| + expect_any_instance_of(ContainerRegistry::Client) + .to receive(:delete_repository_tag_by_name) + .with(repository.path, name) { true } + + expect_any_instance_of(ContainerRegistry::Client) + .not_to receive(:delete_repository_tag_by_digest) + end + end +end |