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
|
|
|
|
|
2022-01-25 13:11:55 -05:00
|
|
|
trait :default do
|
|
|
|
migration_state { 'default' }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :pre_importing do
|
|
|
|
migration_state { 'pre_importing' }
|
|
|
|
migration_pre_import_started_at { Time.zone.now }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :pre_import_done do
|
|
|
|
migration_state { 'pre_import_done' }
|
|
|
|
migration_pre_import_started_at { Time.zone.now }
|
|
|
|
migration_pre_import_done_at { Time.zone.now }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :importing do
|
|
|
|
migration_state { 'importing' }
|
|
|
|
migration_pre_import_started_at { Time.zone.now }
|
|
|
|
migration_pre_import_done_at { Time.zone.now }
|
|
|
|
migration_import_started_at { Time.zone.now }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_done do
|
|
|
|
migration_state { 'import_done' }
|
|
|
|
migration_pre_import_started_at { Time.zone.now }
|
|
|
|
migration_pre_import_done_at { Time.zone.now }
|
|
|
|
migration_import_started_at { Time.zone.now }
|
|
|
|
migration_import_done_at { Time.zone.now }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_aborted do
|
|
|
|
migration_state { 'import_aborted' }
|
|
|
|
migration_pre_import_started_at { Time.zone.now }
|
|
|
|
migration_pre_import_done_at { Time.zone.now }
|
|
|
|
migration_import_started_at { Time.zone.now }
|
|
|
|
migration_aborted_at { Time.zone.now }
|
|
|
|
migration_aborted_in_state { 'importing' }
|
|
|
|
migration_retries_count { 1 }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_skipped do
|
|
|
|
migration_state { 'import_skipped' }
|
|
|
|
migration_skipped_at { Time.zone.now }
|
|
|
|
migration_skipped_reason { :too_many_tags }
|
|
|
|
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)
|
2022-05-26 02:08:37 -04:00
|
|
|
stub_method(repository.client, :repository_tags) do |*args|
|
|
|
|
{
|
2017-03-31 05:54:09 -04:00
|
|
|
'name' => repository.path,
|
2019-10-16 11:06:17 -04:00
|
|
|
'tags' => tags.keys
|
2022-05-26 02:08:37 -04:00
|
|
|
}
|
|
|
|
end
|
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
|