diff options
Diffstat (limited to 'spec/factories')
23 files changed, 284 insertions, 44 deletions
diff --git a/spec/factories/alert_management/alerts.rb b/spec/factories/alert_management/alerts.rb index 01f40a7a465..8724a626d77 100644 --- a/spec/factories/alert_management/alerts.rb +++ b/spec/factories/alert_management/alerts.rb @@ -8,10 +8,23 @@ FactoryBot.define do title { FFaker::Lorem.sentence } started_at { Time.current } + trait :with_validation_errors do + after(:create) do |alert| + too_many_hosts = Array.new(AlertManagement::Alert::HOSTS_MAX_LENGTH + 1) { |_| 'host' } + alert.update_columns(hosts: too_many_hosts) + end + end + trait :with_issue do issue end + trait :with_assignee do |alert| + after(:create) do |alert| + alert.alert_assignees.create(assignee: create(:user)) + end + end + trait :with_fingerprint do fingerprint { SecureRandom.hex } end @@ -70,6 +83,7 @@ FactoryBot.define do trait :all_fields do with_issue + with_assignee with_fingerprint with_service with_monitoring_tool diff --git a/spec/factories/ci/build_report_results.rb b/spec/factories/ci/build_report_results.rb new file mode 100644 index 00000000000..0685c0e5554 --- /dev/null +++ b/spec/factories/ci/build_report_results.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_build_report_result, class: 'Ci::BuildReportResult' do + build factory: :ci_build + project factory: :project + data do + { + tests: { + name: "rspec", + duration: 0.42, + failed: 0, + errored: 2, + skipped: 0, + success: 0 + } + } + end + + trait :with_junit_success do + data do + { + tests: { + name: "rspec", + duration: 0.42, + failed: 0, + errored: 0, + skipped: 0, + success: 2 + } + } + end + end + end +end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 26786aab12c..9403967aa0a 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -378,6 +378,21 @@ FactoryBot.define do end end + trait :release_options do + options do + { + only: 'tags', + script: ['make changelog | tee release_changelog.txt'], + release: { + name: 'Release $CI_COMMIT_SHA', + description: 'Created using the release-cli $EXTRA_DESCRIPTION', + tag_name: 'release-$CI_COMMIT_SHA', + ref: '$CI_COMMIT_SHA' + } + } + end + end + trait :no_options do options { {} } end @@ -400,6 +415,14 @@ FactoryBot.define do end end + trait :secret_detection do + options do + { + artifacts: { reports: { secret_detection: 'gl-secret-detection-report.json' } } + } + end + end + trait :dependency_scanning do options do { diff --git a/spec/factories/ci/job_artifacts.rb b/spec/factories/ci/job_artifacts.rb index 26c09795a0b..1bd4b2826c4 100644 --- a/spec/factories/ci/job_artifacts.rb +++ b/spec/factories/ci/job_artifacts.rb @@ -233,12 +233,9 @@ FactoryBot.define do file_type { :lsif } file_format { :zip } - transient do - file_path { Rails.root.join('spec/fixtures/lsif.json.gz') } - end - after(:build) do |artifact, evaluator| - artifact.file = fixture_file_upload(evaluator.file_path, 'application/x-gzip') + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/lsif.json.zip'), 'application/zip') end end diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index 0b3653a01ed..85cdeaca12c 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -21,6 +21,12 @@ FactoryBot.define do 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? + end + trait :invalid do status { :failed } yaml_errors { 'invalid YAML' } @@ -104,6 +110,7 @@ FactoryBot.define do after(:build) do |pipeline, evaluator| pipeline.builds << build(:ci_build, :terraform_reports, pipeline: pipeline, project: pipeline.project) + pipeline.builds << build(:ci_build, :terraform_reports, pipeline: pipeline, project: pipeline.project) end end @@ -155,6 +162,11 @@ FactoryBot.define do source_sha { merge_request.source_branch_sha } target_sha { merge_request.target_branch_sha } end + + trait :webide do + source { :webide } + config_source { :webide_source } + end end end end diff --git a/spec/factories/ci/ref.rb b/spec/factories/ci/ref.rb index 891d8848a72..bf6fa743743 100644 --- a/spec/factories/ci/ref.rb +++ b/spec/factories/ci/ref.rb @@ -2,15 +2,7 @@ FactoryBot.define do factory :ci_ref, class: 'Ci::Ref' do - ref { 'master' } - status { :success } - tag { false } + ref_path { 'refs/heads/master' } project - - before(:create) do |ref, evaluator| - next if ref.pipelines.exists? - - ref.update!(last_updated_by_pipeline: create(:ci_pipeline, project: evaluator.project, ref: evaluator.ref, tag: evaluator.tag, status: evaluator.status)) - end end end diff --git a/spec/factories/clusters/clusters.rb b/spec/factories/clusters/clusters.rb index 843f87ef7d6..7d0aaa45e40 100644 --- a/spec/factories/clusters/clusters.rb +++ b/spec/factories/clusters/clusters.rb @@ -86,6 +86,23 @@ FactoryBot.define do application_helm factory: %i(clusters_applications_helm installed) end + trait :with_installed_prometheus do + application_prometheus factory: %i(clusters_applications_prometheus installed) + end + + trait :with_all_applications do + application_helm factory: %i(clusters_applications_helm installed) + application_ingress factory: %i(clusters_applications_ingress installed) + application_cert_manager factory: %i(clusters_applications_cert_manager installed) + application_crossplane factory: %i(clusters_applications_crossplane installed) + application_prometheus factory: %i(clusters_applications_prometheus installed) + application_runner factory: %i(clusters_applications_runner installed) + application_jupyter factory: %i(clusters_applications_jupyter installed) + application_knative factory: %i(clusters_applications_knative installed) + application_elastic_stack factory: %i(clusters_applications_elastic_stack installed) + application_fluentd factory: %i(clusters_applications_fluentd installed) + end + trait :with_domain do domain { 'example.com' } end diff --git a/spec/factories/design_management/designs.rb b/spec/factories/design_management/designs.rb index 59d4cc56f95..6d1229063d8 100644 --- a/spec/factories/design_management/designs.rb +++ b/spec/factories/design_management/designs.rb @@ -35,7 +35,7 @@ FactoryBot.define do sha = commit_version[action] version = DesignManagement::Version.new(sha: sha, issue: issue, author: evaluator.author) version.save(validate: false) # We need it to have an ID, validate later - Gitlab::Database.bulk_insert(dv_table_name, [action.row_attrs(version)]) + Gitlab::Database.bulk_insert(dv_table_name, [action.row_attrs(version)]) # rubocop:disable Gitlab/BulkInsert end # always a creation diff --git a/spec/factories/draft_note.rb b/spec/factories/draft_note.rb new file mode 100644 index 00000000000..24563dc92b7 --- /dev/null +++ b/spec/factories/draft_note.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true +FactoryBot.define do + factory :draft_note do + note { generate(:title) } + association :author, factory: :user + association :merge_request, factory: :merge_request + + factory :draft_note_on_text_diff do + transient do + line_number { 14 } + diff_refs { merge_request.try(:diff_refs) } + end + + position do + Gitlab::Diff::Position.new( + old_path: "files/ruby/popen.rb", + new_path: "files/ruby/popen.rb", + old_line: nil, + new_line: line_number, + diff_refs: diff_refs + ) + end + end + + factory :draft_note_on_discussion, traits: [:on_discussion] + + trait :on_discussion do + discussion_id { create(:discussion_note_on_merge_request, noteable: merge_request, project: project).discussion_id } + end + end +end diff --git a/spec/factories/events.rb b/spec/factories/events.rb index ed6cb3505f4..60bb3044191 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -4,27 +4,28 @@ FactoryBot.define do factory :event do project author(factory: :user) { project.creator } - action { Event::JOINED } - - trait(:created) { action { Event::CREATED } } - trait(:updated) { action { Event::UPDATED } } - trait(:closed) { action { Event::CLOSED } } - trait(:reopened) { action { Event::REOPENED } } - trait(:pushed) { action { Event::PUSHED } } - trait(:commented) { action { Event::COMMENTED } } - trait(:merged) { action { Event::MERGED } } - trait(:joined) { action { Event::JOINED } } - trait(:left) { action { Event::LEFT } } - trait(:destroyed) { action { Event::DESTROYED } } - trait(:expired) { action { Event::EXPIRED } } + action { :joined } + + trait(:created) { action { :created } } + trait(:updated) { action { :updated } } + trait(:closed) { action { :closed } } + trait(:reopened) { action { :reopened } } + trait(:pushed) { action { :pushed } } + trait(:commented) { action { :commented } } + trait(:merged) { action { :merged } } + trait(:joined) { action { :joined } } + trait(:left) { action { :left } } + trait(:destroyed) { action { :destroyed } } + trait(:expired) { action { :expired } } + trait(:archived) { action { :archived } } factory :closed_issue_event do - action { Event::CLOSED } + action { :closed } target factory: :closed_issue end factory :wiki_page_event do - action { Event::CREATED } + action { :created } project { @overrides[:wiki_page]&.container || create(:project, :wiki_repo) } target { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) } @@ -33,21 +34,33 @@ FactoryBot.define do end end - trait :for_design do + trait :has_design do transient do design { create(:design, issue: create(:issue, project: project)) } + end + end + + trait :for_design do + has_design + + transient do note { create(:note, author: author, project: project, noteable: design) } end - action { Event::COMMENTED } + action { :commented } target { note } end + + factory :design_event, traits: [:has_design] do + action { :created } + target { design } + end end factory :push_event, class: 'PushEvent' do project factory: :project_empty_repo author(factory: :user) { project.creator } - action { Event::PUSHED } + action { :pushed } end factory :push_event_payload do diff --git a/spec/factories/evidences.rb b/spec/factories/evidences.rb index 77116d8e9ed..dc9fc374103 100644 --- a/spec/factories/evidences.rb +++ b/spec/factories/evidences.rb @@ -3,5 +3,7 @@ FactoryBot.define do factory :evidence, class: 'Releases::Evidence' do release + summary_sha { "760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d" } + summary { { "release": { "tag": "v4.0", "name": "New release", "project_name": "Project name" } } } end end diff --git a/spec/factories/group_import_states.rb b/spec/factories/group_import_states.rb new file mode 100644 index 00000000000..0b491d444fa --- /dev/null +++ b/spec/factories/group_import_states.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :group_import_state, class: 'GroupImportState', traits: %i[created] do + association :group, factory: :group + + trait :created do + status { 0 } + end + + trait :started do + status { 1 } + sequence(:jid) { |n| "group_import_state_#{n}" } + end + + trait :finished do + status { 2 } + sequence(:jid) { |n| "group_import_state_#{n}" } + end + + trait :failed do + status { -1 } + end + end +end diff --git a/spec/factories/keys.rb b/spec/factories/keys.rb index 087d2521836..cf52e772ae0 100644 --- a/spec/factories/keys.rb +++ b/spec/factories/keys.rb @@ -13,6 +13,10 @@ FactoryBot.define do factory :deploy_key, class: 'DeployKey' + factory :group_deploy_key, class: 'GroupDeployKey' do + user + end + factory :personal_key do user end diff --git a/spec/factories/labels.rb b/spec/factories/labels.rb index 81d3e4be6fd..2e783adcc94 100644 --- a/spec/factories/labels.rb +++ b/spec/factories/labels.rb @@ -6,6 +6,18 @@ FactoryBot.define do color { "#990000" } end + trait :described do + description { "Description of #{title}" } + end + + trait :scoped do + transient do + prefix { 'scope' } + end + + title { "#{prefix}::#{generate(:label_title)}" } + end + factory :label, traits: [:base_label], class: 'ProjectLabel' do project diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index b10c04a37f7..2a06690f894 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -109,6 +109,17 @@ FactoryBot.define do end end + trait :with_head_pipeline do + after(:build) do |merge_request| + merge_request.head_pipeline = build( + :ci_pipeline, + :running, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha) + end + end + trait :with_test_reports do after(:build) do |merge_request| merge_request.head_pipeline = build( @@ -133,6 +144,11 @@ FactoryBot.define do end end + trait :unique_branches do + source_branch { generate(:branch) } + target_branch { generate(:branch) } + end + trait :with_coverage_reports do after(:build) do |merge_request| merge_request.head_pipeline = build( diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index 7c3ba122b5a..52e91f31ec1 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -17,17 +17,13 @@ FactoryBot.define do factory :note_on_project_snippet, traits: [:on_project_snippet] factory :note_on_personal_snippet, traits: [:on_personal_snippet] factory :note_on_design, traits: [:on_design] + factory :note_on_alert, traits: [:on_alert] factory :system_note, traits: [:system] factory :discussion_note, class: 'DiscussionNote' factory :discussion_note_on_merge_request, traits: [:on_merge_request], class: 'DiscussionNote' do association :project, :repository - - trait :resolved do - resolved_at { Time.now } - resolved_by { create(:user) } - end end factory :track_mr_picking_note, traits: [:on_merge_request, :system] do @@ -76,11 +72,6 @@ FactoryBot.define do end end - trait :resolved do - resolved_at { Time.now } - resolved_by { create(:user) } - end - factory :image_diff_note_on_merge_request do position do build(:image_diff_position, @@ -155,6 +146,15 @@ FactoryBot.define do end end + trait :on_alert do + noteable { association(:alert_management_alert, project: project) } + end + + trait :resolved do + resolved_at { Time.now } + resolved_by { association(:user) } + end + trait :system do system { true } end @@ -183,6 +183,10 @@ FactoryBot.define do confidential { true } end + trait :with_review do + review + end + transient do in_reply_to { nil } end diff --git a/spec/factories/project_group_links.rb b/spec/factories/project_group_links.rb index b9119a5788b..5e3e83f18c1 100644 --- a/spec/factories/project_group_links.rb +++ b/spec/factories/project_group_links.rb @@ -5,10 +5,15 @@ FactoryBot.define do project group expires_at { nil } + group_access { Gitlab::Access::DEVELOPER } trait(:guest) { group_access { Gitlab::Access::GUEST } } trait(:reporter) { group_access { Gitlab::Access::REPORTER } } trait(:developer) { group_access { Gitlab::Access::DEVELOPER } } trait(:maintainer) { group_access { Gitlab::Access::MAINTAINER } } + + after(:create) do |project_group_link, evaluator| + project_group_link.group.refresh_members_authorized_projects + end end end diff --git a/spec/factories/project_repository_storage_moves.rb b/spec/factories/project_repository_storage_moves.rb index aa8576834eb..b35d5e1d535 100644 --- a/spec/factories/project_repository_storage_moves.rb +++ b/spec/factories/project_repository_storage_moves.rb @@ -10,5 +10,9 @@ FactoryBot.define do trait :scheduled do state { ProjectRepositoryStorageMove.state_machines[:state].states[:scheduled].value } end + + trait :started do + state { ProjectRepositoryStorageMove.state_machines[:state].states[:started].value } + end end end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 45caa7a2b6a..4affab295b8 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -297,6 +297,12 @@ FactoryBot.define do trait :auto_devops_disabled do association :auto_devops, factory: [:project_auto_devops, :disabled] end + + trait :without_container_expiration_policy do + after :create do |project| + project.container_expiration_policy.destroy! + end + end end # Project with empty repository diff --git a/spec/factories/releases/link.rb b/spec/factories/releases/link.rb index 001deeb71a0..da0efe4a749 100644 --- a/spec/factories/releases/link.rb +++ b/spec/factories/releases/link.rb @@ -6,5 +6,6 @@ FactoryBot.define do sequence(:name) { |n| "release-18.#{n}.dmg" } sequence(:url) { |n| "https://example.com/scrambled-url/app-#{n}.zip" } sequence(:filepath) { |n| "/binaries/awesome-app-#{n}" } + link_type { 'other' } end end diff --git a/spec/factories/reviews.rb b/spec/factories/reviews.rb new file mode 100644 index 00000000000..7cf752f1cd9 --- /dev/null +++ b/spec/factories/reviews.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :review do + merge_request + association :project, :repository + author factory: :user + end +end diff --git a/spec/factories/services.rb b/spec/factories/services.rb index b6696769da9..fd97f6abb85 100644 --- a/spec/factories/services.rb +++ b/spec/factories/services.rb @@ -45,9 +45,13 @@ FactoryBot.define do end factory :alerts_service do + active project type { 'AlertsService' } - active { true } + + trait :active do + active { true } + end trait :inactive do active { false } @@ -165,6 +169,13 @@ FactoryBot.define do type { 'SlackService' } end + factory :pipelines_email_service do + project + active { true } + type { 'PipelinesEmailService' } + recipients { 'test@example.com' } + end + # this is for testing storing values inside properties, which is deprecated and will be removed in # https://gitlab.com/gitlab-org/gitlab/issues/29404 trait :without_properties_callback do diff --git a/spec/factories/usage_data.rb b/spec/factories/usage_data.rb index 8fe0018b5a6..c0c5b1103fe 100644 --- a/spec/factories/usage_data.rb +++ b/spec/factories/usage_data.rb @@ -33,6 +33,12 @@ FactoryBot.define do issues = create_list(:issue, 4, project: projects[0]) create_list(:prometheus_alert, 2, project: projects[0]) create(:prometheus_alert, project: projects[1]) + create(:merge_request, :simple, :with_terraform_reports, source_project: projects[0]) + create(:merge_request, :rebased, :with_terraform_reports, source_project: projects[0]) + create(:merge_request, :simple, :with_terraform_reports, source_project: projects[1]) + create(:terraform_state, project: projects[0]) + create(:terraform_state, project: projects[0]) + create(:terraform_state, project: projects[1]) create(:zoom_meeting, project: projects[0], issue: projects[0].issues[0], issue_status: :added) create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[1], issue_status: :removed) create(:zoom_meeting, project: projects[0], issue: projects[0].issues[2], issue_status: :added) @@ -52,6 +58,7 @@ FactoryBot.define do # Alert Issues create(:alert_management_alert, issue: issues[0], project: projects[0]) create(:alert_management_alert, issue: alert_bot_issues[0], project: projects[0]) + create(:self_managed_prometheus_alert_event, related_issues: [issues[1]], project: projects[0]) # Enabled clusters gcp_cluster = create(:cluster_provider_gcp, :created).cluster |