Commit e5539597 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '34196-follow-up-from-handle-tag-delete-404' into 'master'

Resolve "Follow-up from "Handle tag delete 404""

Closes #34196

See merge request gitlab-org/gitlab!18641
parents 0366cda9 44aa0c19
......@@ -69,9 +69,7 @@ class ContainerRepository < ApplicationRecord
digests = tags.map { |tag| tag.digest }.compact.to_set
digests.all? do |digest|
delete_tag_by_digest(digest)
end
digests.map(&method(:delete_tag_by_digest)).all?
end
def delete_tag_by_digest(digest)
......
......@@ -16,19 +16,22 @@ FactoryBot.define do
after(:build) do |repository, evaluator|
next if evaluator.tags.to_a.none?
tags = evaluator.tags
# convert Array into Hash
tags = tags.product(['sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15']).to_h unless tags.is_a?(Hash)
allow(repository.client)
.to receive(:repository_tags)
.and_return({
'name' => repository.path,
'tags' => evaluator.tags
'tags' => tags.keys
})
evaluator.tags.each do |tag|
tags.each_pair do |tag, digest|
allow(repository.client)
.to receive(:repository_tag_digest)
.with(repository.path, tag)
.and_return('sha256:4c8e63ca4cb663ce6c688cb06f1c3' \
'72b088dac5b6d7ad7d49cd620d85cf72a15')
.and_return(digest)
end
end
end
......
......@@ -78,7 +78,7 @@ describe ContainerRepository do
describe '#delete_tags!' do
let(:repository) do
create(:container_repository, name: 'my_image',
tags: %w[latest rc1],
tags: { latest: '123', rc1: '234' },
project: project)
end
......@@ -86,6 +86,7 @@ describe ContainerRepository do
it 'returns status that indicates success' do
expect(repository.client)
.to receive(:delete_repository_tag)
.twice
.and_return(true)
expect(repository.delete_tags!).to be_truthy
......@@ -96,6 +97,7 @@ describe ContainerRepository do
it 'returns status that indicates failure' do
expect(repository.client)
.to receive(:delete_repository_tag)
.twice
.and_return(false)
expect(repository.delete_tags!).to be_falsey
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment