2019-07-25 05:11:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-14 00:13:44 +00:00
|
|
|
FactoryBot.define do
|
2020-01-09 18:07:52 +00:00
|
|
|
factory :environment, class: 'Environment' do
|
2016-06-14 11:51:12 +00:00
|
|
|
sequence(:name) { |n| "environment#{n}" }
|
|
|
|
|
2017-08-02 19:55:11 +00:00
|
|
|
association :project, :repository
|
2016-07-26 07:35:47 +00:00
|
|
|
sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" }
|
2016-11-09 08:42:09 +00:00
|
|
|
|
2020-04-08 00:09:30 +00:00
|
|
|
trait :available do
|
|
|
|
state { :available }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :stopped do
|
|
|
|
state { :stopped }
|
|
|
|
end
|
|
|
|
|
2021-03-05 00:09:24 +00:00
|
|
|
trait :production do
|
2021-06-01 21:10:06 +00:00
|
|
|
name { 'production' }
|
2021-03-05 00:09:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :staging do
|
2021-06-01 21:10:06 +00:00
|
|
|
name { 'staging' }
|
2021-03-05 00:09:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :testing do
|
2021-06-01 21:10:06 +00:00
|
|
|
name { 'testing' }
|
2021-03-05 00:09:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :development do
|
2021-06-01 21:10:06 +00:00
|
|
|
name { 'development' }
|
2021-03-05 00:09:24 +00:00
|
|
|
end
|
|
|
|
|
2016-11-09 08:42:09 +00:00
|
|
|
trait :with_review_app do |environment|
|
2021-03-12 03:08:56 +00:00
|
|
|
sequence(:name) { |n| "review/#{n}" }
|
|
|
|
|
2016-11-14 13:10:54 +00:00
|
|
|
transient do
|
2019-10-02 00:06:26 +00:00
|
|
|
ref { 'master' }
|
2016-11-14 13:10:54 +00:00
|
|
|
end
|
|
|
|
|
2016-11-09 08:42:09 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2016-11-14 13:10:54 +00:00
|
|
|
after(:create) do |environment, evaluator|
|
2017-04-06 12:28:40 +00:00
|
|
|
pipeline = create(:ci_pipeline, project: environment.project)
|
|
|
|
|
2022-05-30 15:08:03 +00:00
|
|
|
deployable = create(:ci_build, :success, name: "#{environment.name}:deploy",
|
2022-08-22 12:12:54 +00:00
|
|
|
pipeline: pipeline)
|
2017-04-06 13:19:52 +00:00
|
|
|
|
2016-11-09 08:42:09 +00:00
|
|
|
deployment = create(:deployment,
|
2018-11-05 00:37:40 +00:00
|
|
|
:success,
|
2016-11-09 08:42:09 +00:00
|
|
|
environment: environment,
|
|
|
|
project: environment.project,
|
2017-04-06 13:19:52 +00:00
|
|
|
deployable: deployable,
|
2016-11-14 13:10:54 +00:00
|
|
|
ref: evaluator.ref,
|
|
|
|
sha: environment.project.commit(evaluator.ref).id)
|
2016-11-09 08:42:09 +00:00
|
|
|
|
|
|
|
teardown_build = create(:ci_build, :manual,
|
2017-04-06 13:19:52 +00:00
|
|
|
name: "#{environment.name}:teardown",
|
2017-04-06 12:28:40 +00:00
|
|
|
pipeline: pipeline)
|
2016-11-09 08:42:09 +00:00
|
|
|
|
|
|
|
deployment.update_column(:on_stop, teardown_build.name)
|
|
|
|
environment.update_attribute(:deployments, [deployment])
|
|
|
|
end
|
|
|
|
end
|
2017-04-04 08:14:46 +00:00
|
|
|
|
|
|
|
trait :non_playable do
|
2019-10-02 00:06:26 +00:00
|
|
|
status { 'created' }
|
|
|
|
self.when { 'manual' }
|
2017-04-04 08:14:46 +00:00
|
|
|
end
|
2019-12-10 07:53:40 +00:00
|
|
|
|
2020-02-14 00:09:07 +00:00
|
|
|
trait :auto_stoppable do
|
2019-12-10 07:53:40 +00:00
|
|
|
auto_stop_at { 1.day.ago }
|
|
|
|
end
|
|
|
|
|
2021-07-29 15:09:48 +00:00
|
|
|
trait :auto_deletable do
|
|
|
|
state { :stopped }
|
|
|
|
auto_delete_at { 1.day.ago }
|
|
|
|
end
|
|
|
|
|
2019-12-10 07:53:40 +00:00
|
|
|
trait :will_auto_stop do
|
|
|
|
auto_stop_at { 1.day.from_now }
|
|
|
|
end
|
2016-06-14 11:51:12 +00:00
|
|
|
end
|
|
|
|
end
|