2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2017-03-23 09:37:17 -04:00
|
|
|
factory :container_repository do
|
2019-08-01 08:03:08 -04:00
|
|
|
sequence(:name) { |n| "test_image_#{n}" }
|
2017-03-23 09:37:17 -04:00
|
|
|
project
|
|
|
|
|
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
tags { [] }
|
2017-03-23 09:37:17 -04:00
|
|
|
end
|
|
|
|
|
2017-04-03 06:49:54 -04:00
|
|
|
trait :root do
|
2019-10-01 20:06:26 -04:00
|
|
|
name { '' }
|
2017-04-03 06:49:54 -04:00
|
|
|
end
|
|
|
|
|
2020-10-22 11:08:25 -04:00
|
|
|
trait :status_delete_scheduled do
|
|
|
|
status { :delete_scheduled }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :status_delete_failed do
|
|
|
|
status { :delete_failed }
|
|
|
|
end
|
|
|
|
|
2020-10-26 14:08:27 -04:00
|
|
|
trait :cleanup_scheduled do
|
|
|
|
expiration_policy_cleanup_status { :cleanup_scheduled }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :cleanup_unfinished do
|
|
|
|
expiration_policy_cleanup_status { :cleanup_unfinished }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :cleanup_ongoing do
|
|
|
|
expiration_policy_cleanup_status { :cleanup_ongoing }
|
|
|
|
end
|
|
|
|
|
2017-03-24 07:31:34 -04:00
|
|
|
after(:build) do |repository, evaluator|
|
2017-03-31 05:54:09 -04:00
|
|
|
next if evaluator.tags.to_a.none?
|
|
|
|
|
2019-10-16 11:06:17 -04:00
|
|
|
tags = evaluator.tags
|
|
|
|
# convert Array into Hash
|
|
|
|
tags = tags.product(['sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15']).to_h unless tags.is_a?(Hash)
|
|
|
|
|
2017-03-31 05:54:09 -04:00
|
|
|
allow(repository.client)
|
|
|
|
.to receive(:repository_tags)
|
|
|
|
.and_return({
|
|
|
|
'name' => repository.path,
|
2019-10-16 11:06:17 -04:00
|
|
|
'tags' => tags.keys
|
2017-03-31 05:54:09 -04:00
|
|
|
})
|
|
|
|
|
2019-10-16 11:06:17 -04:00
|
|
|
tags.each_pair do |tag, digest|
|
2017-03-24 07:31:34 -04:00
|
|
|
allow(repository.client)
|
2017-03-31 05:54:09 -04:00
|
|
|
.to receive(:repository_tag_digest)
|
|
|
|
.with(repository.path, tag)
|
2019-10-16 11:06:17 -04:00
|
|
|
.and_return(digest)
|
2017-03-24 07:31:34 -04:00
|
|
|
end
|
2017-03-23 09:37:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|