Welcome to mirror list, hosted at ThFree Co, Russian Federation.

container_repositories.rb « factories « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 86bb129067fbf280c9cfde39ab08f533a9aada5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

FactoryBot.define do
  factory :container_repository do
    sequence(:name) { |n| "test_image_#{n}" }
    project

    transient do
      tags { [] }
    end

    trait :root do
      name { '' }
    end

    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

    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' => tags.keys
        })

      tags.each_pair do |tag, digest|
        allow(repository.client)
          .to receive(:repository_tag_digest)
          .with(repository.path, tag)
          .and_return(digest)
      end
    end
  end
end