summaryrefslogtreecommitdiff
path: root/spec/factories/terraform/state.rb
blob: 9decc89ef39d5645a25f7c7e4dd2af4f018db906 (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
# frozen_string_literal: true

FactoryBot.define do
  factory :terraform_state, class: 'Terraform::State' do
    project { create(:project) }

    sequence(:name) { |n| "state-#{n}" }

    trait :with_file do
      versioning_enabled { false }
      file { fixture_file_upload('spec/fixtures/terraform/terraform.tfstate', 'application/json') }
    end

    trait :locked do
      sequence(:lock_xid) { |n| "lock-#{n}" }
      locked_at { Time.current }
      locked_by_user { create(:user) }
    end

    trait(:checksummed) do
      with_file
      verification_checksum { 'abc' }
    end

    trait(:checksum_failure) do
      with_file
      verification_failure { 'Could not calculate the checksum' }
    end

    trait :with_version do
      after(:create) do |state|
        create(:terraform_state_version, :with_file, terraform_state: state)
      end
    end

    # Remove with https://gitlab.com/gitlab-org/gitlab/-/issues/235108
    factory :legacy_terraform_state, parent: :terraform_state, traits: [:with_file]
  end
end