debian-mirror-gitlab/spec/factories/environments.rb

88 lines
2.3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2020-03-13 15:44:24 +05:30
factory :environment, class: 'Environment' do
sequence(:name) { |n| "environment#{n}" }
2017-09-10 17:25:29 +05:30
association :project, :repository
2016-09-13 17:45:13 +05:30
sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" }
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
trait :available do
state { :available }
end
trait :stopped do
state { :stopped }
end
2021-04-17 20:07:23 +05:30
trait :production do
2021-09-04 01:27:46 +05:30
name { 'production' }
2021-04-17 20:07:23 +05:30
end
trait :staging do
2021-09-04 01:27:46 +05:30
name { 'staging' }
2021-04-17 20:07:23 +05:30
end
trait :testing do
2021-09-04 01:27:46 +05:30
name { 'testing' }
2021-04-17 20:07:23 +05:30
end
trait :development do
2021-09-04 01:27:46 +05:30
name { 'development' }
2021-04-17 20:07:23 +05:30
end
2017-08-17 22:00:37 +05:30
trait :with_review_app do |environment|
2021-04-17 20:07:23 +05:30
sequence(:name) { |n| "review/#{n}" }
2017-08-17 22:00:37 +05:30
transient do
2019-12-21 20:55:43 +05:30
ref { 'master' }
2017-08-17 22:00:37 +05:30
end
# At this point `review app` is an ephemeral concept related to
# deployments being deployed for given environment. There is no
# first-class `review app` available so we need to create set of
# interconnected objects to simulate a review app.
#
after(:create) do |environment, evaluator|
pipeline = create(:ci_pipeline, project: environment.project)
2022-07-23 23:45:48 +05:30
deployable = create(:ci_build, :success, name: "#{environment.name}:deploy",
2022-10-11 01:57:18 +05:30
pipeline: pipeline)
2017-08-17 22:00:37 +05:30
deployment = create(:deployment,
2018-12-13 13:39:08 +05:30
:success,
2017-08-17 22:00:37 +05:30
environment: environment,
project: environment.project,
deployable: deployable,
ref: evaluator.ref,
sha: environment.project.commit(evaluator.ref).id)
teardown_build = create(:ci_build, :manual,
name: "#{environment.name}:teardown",
pipeline: pipeline)
deployment.update_column(:on_stop, teardown_build.name)
environment.update_attribute(:deployments, [deployment])
end
end
trait :non_playable do
2019-12-21 20:55:43 +05:30
status { 'created' }
self.when { 'manual' }
2017-08-17 22:00:37 +05:30
end
2020-01-01 13:55:28 +05:30
2020-03-13 15:44:24 +05:30
trait :auto_stoppable do
2020-01-01 13:55:28 +05:30
auto_stop_at { 1.day.ago }
end
2021-10-27 15:23:28 +05:30
trait :auto_deletable do
state { :stopped }
auto_delete_at { 1.day.ago }
end
2020-01-01 13:55:28 +05:30
trait :will_auto_stop do
auto_stop_at { 1.day.from_now }
end
end
end