debian-mirror-gitlab/spec/factories/ci/builds.rb

362 lines
7.2 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
include ActionDispatch::TestProcess
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2015-09-25 12:07:36 +05:30
factory :ci_build, class: Ci::Build do
2015-10-24 18:46:33 +05:30
name 'test'
2016-08-24 12:49:21 +05:30
stage 'test'
stage_idx 0
2015-10-24 18:46:33 +05:30
ref 'master'
tag false
2018-03-17 18:26:18 +05:30
protected false
created_at 'Di 29. Okt 09:50:00 CET 2013'
pending
2017-08-17 22:00:37 +05:30
2015-09-25 12:07:36 +05:30
options do
{
2017-08-17 22:00:37 +05:30
image: 'ruby:2.1',
2019-02-15 15:39:39 +05:30
services: ['postgres'],
script: ['ls -a']
2015-09-25 12:07:36 +05:30
}
end
2017-08-17 22:00:37 +05:30
2016-08-24 12:49:21 +05:30
yaml_variables do
[
2017-08-17 22:00:37 +05:30
{ key: 'DB_NAME', value: 'postgres', public: true }
2016-08-24 12:49:21 +05:30
]
end
2015-09-25 12:07:36 +05:30
pipeline factory: :ci_pipeline
2015-09-25 12:07:36 +05:30
2018-12-13 13:39:08 +05:30
trait :degenerated do
options nil
yaml_variables nil
end
2018-03-17 18:26:18 +05:30
trait :started do
started_at 'Di 29. Okt 09:51:28 CET 2013'
end
trait :finished do
started
finished_at 'Di 29. Okt 09:53:28 CET 2013'
end
2016-04-02 18:10:28 +05:30
trait :success do
2018-03-17 18:26:18 +05:30
finished
2016-04-02 18:10:28 +05:30
status 'success'
end
trait :failed do
2018-03-17 18:26:18 +05:30
finished
2016-04-02 18:10:28 +05:30
status 'failed'
end
trait :canceled do
2018-03-17 18:26:18 +05:30
finished
status 'canceled'
end
2017-08-17 22:00:37 +05:30
trait :skipped do
2018-03-17 18:26:18 +05:30
started
2017-08-17 22:00:37 +05:30
status 'skipped'
end
2016-04-02 18:10:28 +05:30
trait :running do
2018-03-17 18:26:18 +05:30
started
2016-04-02 18:10:28 +05:30
status 'running'
end
trait :pending do
2018-10-15 14:42:47 +05:30
queued_at 'Di 29. Okt 09:50:59 CET 2013'
2016-04-02 18:10:28 +05:30
status 'pending'
end
2016-09-13 17:45:13 +05:30
trait :created do
status 'created'
end
2019-07-07 11:18:12 +05:30
trait :preparing do
status 'preparing'
end
2018-12-05 23:21:45 +05:30
trait :scheduled do
schedulable
status 'scheduled'
2019-03-02 22:35:43 +05:30
scheduled_at { 1.minute.since }
2018-12-05 23:21:45 +05:30
end
trait :expired_scheduled do
schedulable
status 'scheduled'
scheduled_at { 1.minute.ago }
end
2016-08-24 12:49:21 +05:30
trait :manual do
2017-08-17 22:00:37 +05:30
status 'manual'
2016-08-24 12:49:21 +05:30
self.when 'manual'
end
2017-08-17 22:00:37 +05:30
trait :teardown_environment do
environment 'staging'
2019-02-15 15:39:39 +05:30
options do
{
script: %w(ls),
environment: { name: 'staging',
action: 'stop',
url: 'http://staging.example.com/$CI_JOB_NAME' }
}
end
2017-08-17 22:00:37 +05:30
end
2018-12-13 13:39:08 +05:30
trait :deploy_to_production do
environment 'production'
2019-02-15 15:39:39 +05:30
options do
{
script: %w(ls),
environment: { name: 'production',
url: 'http://prd.example.com/$CI_JOB_NAME' }
}
end
2018-12-13 13:39:08 +05:30
end
trait :start_review_app do
environment 'review/$CI_COMMIT_REF_NAME'
2019-02-15 15:39:39 +05:30
options do
{
script: %w(ls),
environment: { name: 'review/$CI_COMMIT_REF_NAME',
url: 'http://staging.example.com/$CI_JOB_NAME',
on_stop: 'stop_review_app' }
}
end
2018-12-13 13:39:08 +05:30
end
trait :stop_review_app do
name 'stop_review_app'
environment 'review/$CI_COMMIT_REF_NAME'
2019-02-15 15:39:39 +05:30
options do
{
script: %w(ls),
environment: { name: 'review/$CI_COMMIT_REF_NAME',
url: 'http://staging.example.com/$CI_JOB_NAME',
action: 'stop' }
}
end
2018-12-13 13:39:08 +05:30
end
2017-08-17 22:00:37 +05:30
2016-04-02 18:10:28 +05:30
trait :allowed_to_fail do
allow_failure true
end
2017-08-17 22:00:37 +05:30
trait :ignored do
allowed_to_fail
end
trait :playable do
manual
end
trait :retryable do
success
end
2018-12-05 23:21:45 +05:30
trait :schedulable do
self.when 'delayed'
2019-02-15 15:39:39 +05:30
options do
{
script: ['ls -a'],
start_in: '1 minute'
}
end
2018-12-05 23:21:45 +05:30
end
trait :actionable do
self.when 'manual'
end
2017-09-10 17:25:29 +05:30
trait :retried do
retried true
end
2017-08-17 22:00:37 +05:30
trait :cancelable do
pending
end
trait :erasable do
success
artifacts
end
trait :tags do
tag_list [:docker, :ruby]
end
trait :on_tag do
tag true
end
trait :triggered do
2018-03-17 18:26:18 +05:30
trigger_request factory: :ci_trigger_request
2017-08-17 22:00:37 +05:30
end
2015-12-23 02:04:40 +05:30
after(:build) do |build, evaluator|
2017-09-10 17:25:29 +05:30
build.project ||= build.pipeline.project
2015-12-23 02:04:40 +05:30
end
2018-03-17 18:26:18 +05:30
trait :tag do
2015-10-24 18:46:33 +05:30
tag true
end
2017-08-17 22:00:37 +05:30
trait :coverage do
2016-06-02 11:05:42 +05:30
coverage 99.9
2017-08-17 22:00:37 +05:30
coverage_regex '/(d+)/'
2016-06-02 11:05:42 +05:30
end
2018-03-17 18:26:18 +05:30
trait :trace_live do
2016-04-02 18:10:28 +05:30
after(:create) do |build, evaluator|
2017-08-17 22:00:37 +05:30
build.trace.set('BUILD TRACE')
end
end
2016-04-02 18:10:28 +05:30
2018-03-17 18:26:18 +05:30
trait :trace_artifact do
after(:create) do |build, evaluator|
create(:ci_job_artifact, :trace, job: build)
end
end
2019-09-04 21:01:54 +05:30
trait :trace_with_duplicate_sections do
after(:create) do |build, evaluator|
trace = File.binread(
File.expand_path(
Rails.root.join('spec/fixtures/trace/trace_with_duplicate_sections')))
build.trace.set(trace)
end
end
trait :trace_with_sections do
after(:create) do |build, evaluator|
trace = File.binread(
File.expand_path(
Rails.root.join('spec/fixtures/trace/trace_with_sections')))
build.trace.set(trace)
end
end
2018-03-17 18:26:18 +05:30
trait :unicode_trace_live do
2017-09-10 17:25:29 +05:30
after(:create) do |build, evaluator|
trace = File.binread(
File.expand_path(
Rails.root.join('spec/fixtures/trace/ansi-sequence-and-unicode')))
build.trace.set(trace)
end
end
2017-08-17 22:00:37 +05:30
trait :erased do
2018-12-05 23:21:45 +05:30
erased_at { Time.now }
2017-08-17 22:00:37 +05:30
erased_by factory: :user
end
trait :queued do
2018-12-05 23:21:45 +05:30
queued_at { Time.now }
2017-08-17 22:00:37 +05:30
runner factory: :ci_runner
end
2018-03-17 18:26:18 +05:30
trait :artifacts do
after(:create) do |build|
create(:ci_job_artifact, :archive, job: build, expire_at: build.artifacts_expire_at)
create(:ci_job_artifact, :metadata, job: build, expire_at: build.artifacts_expire_at)
build.reload
2016-09-13 17:45:13 +05:30
end
end
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
trait :test_reports do
after(:build) do |build|
build.job_artifacts << create(:ci_job_artifact, :junit, job: build)
end
end
2018-03-17 18:26:18 +05:30
trait :expired do
2018-12-05 23:21:45 +05:30
artifacts_expire_at { 1.minute.ago }
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
trait :with_commit do
after(:build) do |build|
allow(build).to receive(:commit).and_return build(:commit, :without_author)
end
end
trait :with_commit_and_author do
after(:build) do |build|
allow(build).to receive(:commit).and_return build(:commit)
end
end
trait :extended_options do
options do
{
2017-09-10 17:25:29 +05:30
image: { name: 'ruby:2.1', entrypoint: '/bin/sh' },
2018-10-15 14:42:47 +05:30
services: ['postgres', { name: 'docker:stable-dind', entrypoint: '/bin/sh', command: 'sleep 30', alias: 'docker' }],
2019-02-15 15:39:39 +05:30
script: %w(echo),
2017-08-17 22:00:37 +05:30
after_script: %w(ls date),
artifacts: {
name: 'artifacts_file',
untracked: false,
paths: ['out/'],
when: 'always',
expire_in: '7d'
},
cache: {
key: 'cache_key',
untracked: false,
2017-09-10 17:25:29 +05:30
paths: ['vendor/*'],
policy: 'pull-push'
2017-08-17 22:00:37 +05:30
}
}
end
end
trait :no_options do
options { {} }
end
trait :non_playable do
status 'created'
self.when 'manual'
end
2018-03-17 18:26:18 +05:30
trait :protected do
protected true
end
2018-05-09 12:01:36 +05:30
trait :script_failure do
failed
failure_reason 1
end
2018-10-15 14:42:47 +05:30
trait :api_failure do
failed
failure_reason 2
end
2018-11-08 19:23:39 +05:30
2019-07-07 11:18:12 +05:30
trait :prerequisite_failure do
failed
failure_reason 10
end
2018-11-08 19:23:39 +05:30
trait :with_runner_session do
after(:build) do |build|
2018-11-29 20:51:05 +05:30
build.build_runner_session(url: 'https://localhost')
2018-11-08 19:23:39 +05:30
end
end
2015-09-25 12:07:36 +05:30
end
end