2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
FactoryBot.define do
|
2017-08-17 22:00:37 +05:30
|
|
|
factory :container_repository do
|
2019-10-12 21:52:04 +05:30
|
|
|
sequence(:name) { |n| "test_image_#{n}" }
|
2017-08-17 22:00:37 +05:30
|
|
|
project
|
|
|
|
|
|
|
|
transient do
|
2019-12-21 20:55:43 +05:30
|
|
|
tags { [] }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
trait :root do
|
2019-12-21 20:55:43 +05:30
|
|
|
name { '' }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
trait :status_delete_scheduled do
|
|
|
|
status { :delete_scheduled }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :status_delete_failed do
|
|
|
|
status { :delete_failed }
|
|
|
|
end
|
|
|
|
|
|
|
|
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-04-04 11:22:00 +05:30
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
after(:build) do |repository, evaluator|
|
|
|
|
next if evaluator.tags.to_a.none?
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
tags = evaluator.tags
|
|
|
|
# convert Array into Hash
|
|
|
|
tags = tags.product(['sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15']).to_h unless tags.is_a?(Hash)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
allow(repository.client)
|
|
|
|
.to receive(:repository_tags)
|
|
|
|
.and_return({
|
|
|
|
'name' => repository.path,
|
2019-12-21 20:55:43 +05:30
|
|
|
'tags' => tags.keys
|
2017-08-17 22:00:37 +05:30
|
|
|
})
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
tags.each_pair do |tag, digest|
|
2017-08-17 22:00:37 +05:30
|
|
|
allow(repository.client)
|
|
|
|
.to receive(:repository_tag_digest)
|
|
|
|
.with(repository.path, tag)
|
2019-12-21 20:55:43 +05:30
|
|
|
.and_return(digest)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|