# frozen_string_literal: true
FactoryBot.define do
# TODO: we can remove this factory in favour of :ci_pipeline
factory :ci_empty_pipeline, class: 'Ci::Pipeline' do
source { :push }
ref { 'master' }
sha { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' }
status { 'pending' }
add_attribute(:protected) { false }
project
# Persist merge request head_pipeline_id
# on pipeline factories to avoid circular references
transient { head_pipeline_of { nil } }
after(:create) do |pipeline, evaluator|
merge_request = evaluator.head_pipeline_of
merge_request&.update(head_pipeline: pipeline)
end
factory :ci_pipeline do
transient { ci_ref_presence { true } }
after(:build) do |pipeline, evaluator|
pipeline.ensure_ci_ref! if evaluator.ci_ref_presence && pipeline.ci_ref_id.nil?
trait :invalid do
status { :failed }
yaml_errors { 'invalid YAML' }
failure_reason { :config_error }
trait :created do
status { :created }
trait :preparing do
status { :preparing }
trait :blocked do
status { :manual }
trait :scheduled do
status { :scheduled }
trait :success do
status { :success }
trait :running do
status { :running }
trait :failed do
trait :protected do
add_attribute(:protected) { true }
trait :with_report_results do
pipeline.builds << build(:ci_build, :report_results, pipeline: pipeline, project: pipeline.project)
trait :with_test_reports do
pipeline.builds << build(:ci_build, :test_reports, pipeline: pipeline, project: pipeline.project)
trait :with_test_reports_attachment do
pipeline.builds << build(:ci_build, :test_reports_with_attachment, pipeline: pipeline, project: pipeline.project)
trait :with_broken_test_reports do
after(:build) do |pipeline, _evaluator|
pipeline.builds << build(:ci_build, :broken_test_reports, pipeline: pipeline, project: pipeline.project)
trait :with_accessibility_reports do
pipeline.builds << build(:ci_build, :accessibility_reports, pipeline: pipeline, project: pipeline.project)
trait :with_coverage_reports do
pipeline.builds << build(:ci_build, :coverage_reports, pipeline: pipeline, project: pipeline.project)
trait :with_terraform_reports do
pipeline.builds << build(:ci_build, :terraform_reports, pipeline: pipeline, project: pipeline.project)
trait :with_exposed_artifacts do
pipeline.builds << build(:ci_build, :artifacts,
pipeline: pipeline,
project: pipeline.project,
options: { artifacts: { expose_as: 'the artifact', paths: ['ci_artifacts.txt'] } })
trait :with_job do
pipeline.builds << build(:ci_build, pipeline: pipeline, project: pipeline.project)
trait :auto_devops_source do
config_source { Ci::Pipeline.config_sources[:auto_devops_source] }
trait :repository_source do
config_source { Ci::Pipeline.config_sources[:repository_source] }
trait :detached_merge_request_pipeline do
merge_request
source { :merge_request_event }
project { merge_request.source_project }
sha { merge_request.source_branch_sha }
ref { merge_request.ref_path }
trait :legacy_detached_merge_request_pipeline do
detached_merge_request_pipeline
ref { merge_request.source_branch }
trait :merged_result_pipeline do
sha { 'test-merge-sha'}
ref { merge_request.merge_ref_path }
source_sha { merge_request.source_branch_sha }
target_sha { merge_request.target_branch_sha }
trait :webide do
source { :webide }
config_source { :webide_source }