diff options
Diffstat (limited to 'spec/factories')
26 files changed, 200 insertions, 112 deletions
diff --git a/spec/factories/bulk_import/entities.rb b/spec/factories/bulk_import/entities.rb index cf31ffec4f6..eeb4f8325ae 100644 --- a/spec/factories/bulk_import/entities.rb +++ b/spec/factories/bulk_import/entities.rb @@ -9,6 +9,7 @@ FactoryBot.define do sequence(:destination_namespace) { |n| "destination-path-#{n}" } destination_name { 'Imported Entity' } + sequence(:source_xid) trait(:group_entity) do source_type { :group_entity } diff --git a/spec/factories/ci/build_metadata.rb b/spec/factories/ci/build_metadata.rb index cfc86c4ef4b..a0a5305ef39 100644 --- a/spec/factories/ci/build_metadata.rb +++ b/spec/factories/ci/build_metadata.rb @@ -3,5 +3,9 @@ FactoryBot.define do factory :ci_build_metadata, class: 'Ci::BuildMetadata' do build { association(:ci_build, strategy: :build, metadata: instance) } + + after(:build) do |metadata| + metadata.build&.valid? + end end end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 8c2edc8cd9f..9a3b2837ab8 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -424,79 +424,79 @@ FactoryBot.define do trait :codequality_report do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :codequality, job: build) + build.job_artifacts << build(:ci_job_artifact, :codequality, job: build) end end trait :sast_report do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :sast, job: build) + build.job_artifacts << build(:ci_job_artifact, :sast, job: build) end end trait :secret_detection_report do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :secret_detection, job: build) + build.job_artifacts << build(:ci_job_artifact, :secret_detection, job: build) end end trait :test_reports do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :junit, job: build) + build.job_artifacts << build(:ci_job_artifact, :junit, job: build) end end trait :test_reports_with_attachment do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :junit_with_attachment, job: build) + build.job_artifacts << build(:ci_job_artifact, :junit_with_attachment, job: build) end end trait :broken_test_reports do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :junit_with_corrupted_data, job: build) + build.job_artifacts << build(:ci_job_artifact, :junit_with_corrupted_data, job: build) end end trait :test_reports_with_duplicate_failed_test_names do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :junit_with_duplicate_failed_test_names, job: build) + build.job_artifacts << build(:ci_job_artifact, :junit_with_duplicate_failed_test_names, job: build) end end trait :test_reports_with_three_failures do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :junit_with_three_failures, job: build) + build.job_artifacts << build(:ci_job_artifact, :junit_with_three_failures, job: build) end end trait :accessibility_reports do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :accessibility, job: build) + build.job_artifacts << build(:ci_job_artifact, :accessibility, job: build) end end trait :coverage_reports do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :cobertura, job: build) + build.job_artifacts << build(:ci_job_artifact, :cobertura, job: build) end end trait :codequality_reports do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :codequality, job: build) + build.job_artifacts << build(:ci_job_artifact, :codequality, job: build) end end trait :codequality_reports_without_degradation do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :codequality_without_errors, job: build) + build.job_artifacts << build(:ci_job_artifact, :codequality_without_errors, job: build) end end trait :terraform_reports do after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :terraform, job: build) + build.job_artifacts << build(:ci_job_artifact, :terraform, job: build) end end diff --git a/spec/factories/ci/job_artifacts.rb b/spec/factories/ci/job_artifacts.rb index f8b964cf8e0..304d77e8521 100644 --- a/spec/factories/ci/job_artifacts.rb +++ b/spec/factories/ci/job_artifacts.rb @@ -352,6 +352,18 @@ FactoryBot.define do end end + # Equivalent Semgrep report for combined :sast_bandit and :sast_gosec reports. + # This report includes signature tracking. + trait :sast_semgrep_for_multiple_findings do + file_type { :sast } + file_format { :raw } + + after(:build) do |artifact, _| + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/security_reports/master/gl-sast-report-semgrep-for-multiple-findings.json'), 'application/json') + end + end + trait :common_security_report do file_format { :raw } file_type { :dependency_scanning } @@ -381,16 +393,6 @@ FactoryBot.define do end end - trait :sast_deprecated do - file_type { :sast } - file_format { :raw } - - after(:build) do |artifact, _| - artifact.file = fixture_file_upload( - Rails.root.join('spec/fixtures/security_reports/deprecated/gl-sast-report.json'), 'application/json') - end - end - trait :sast_with_corrupted_data do file_type { :sast } file_format { :raw } diff --git a/spec/factories/ci/pipeline_artifacts.rb b/spec/factories/ci/pipeline_artifacts.rb index d096f149c3a..bdd390126dd 100644 --- a/spec/factories/ci/pipeline_artifacts.rb +++ b/spec/factories/ci/pipeline_artifacts.rb @@ -17,6 +17,11 @@ FactoryBot.define do association :pipeline, :unlocked, factory: :ci_pipeline end + trait :artifact_unlocked do + association :pipeline, :unlocked, factory: :ci_pipeline + locked { :unlocked } + end + trait :checksummed do verification_checksum { 'abc' } end diff --git a/spec/factories/ci/pipeline_metadata.rb b/spec/factories/ci/pipeline_metadata.rb new file mode 100644 index 00000000000..600cfaa92c6 --- /dev/null +++ b/spec/factories/ci/pipeline_metadata.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_pipeline_metadata, class: 'Ci::PipelineMetadata' do + title { 'Pipeline title' } + + pipeline factory: :ci_empty_pipeline + project + end +end diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index d6b1da1d5c2..650b8647237 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -8,6 +8,7 @@ FactoryBot.define do sha { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' } status { 'pending' } add_attribute(:protected) { false } + partition_id { 1234 } project @@ -18,6 +19,8 @@ FactoryBot.define do transient { child_of { nil } } transient { upstream_of { nil } } + transient { title { nil } } + after(:build) do |pipeline, evaluator| if evaluator.child_of pipeline.project = evaluator.child_of.project @@ -25,6 +28,10 @@ FactoryBot.define do end pipeline.ensure_project_iid! + + if evaluator.title + pipeline.pipeline_metadata = build(:ci_pipeline_metadata, title: evaluator.title, project: pipeline.project, pipeline: pipeline) + end end after(:create) do |pipeline, evaluator| @@ -47,6 +54,7 @@ FactoryBot.define do end factory :ci_pipeline do + partition_id { 1234 } transient { ci_ref_presence { true } } before(:create) do |pipeline, evaluator| diff --git a/spec/factories/ci/reports/sbom/components.rb b/spec/factories/ci/reports/sbom/components.rb index 317e1c863cf..fd9b4386130 100644 --- a/spec/factories/ci/reports/sbom/components.rb +++ b/spec/factories/ci/reports/sbom/components.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :ci_reports_sbom_component, class: '::Gitlab::Ci::Reports::Sbom::Component' do - type { :library } + type { "library" } sequence(:name) { |n| "component-#{n}" } sequence(:version) { |n| "v0.0.#{n}" } diff --git a/spec/factories/ci/reports/sbom/reports.rb b/spec/factories/ci/reports/sbom/reports.rb new file mode 100644 index 00000000000..4a83b5898ef --- /dev/null +++ b/spec/factories/ci/reports/sbom/reports.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_reports_sbom_report, class: '::Gitlab::Ci::Reports::Sbom::Report' do + transient do + num_components { 5 } + components { build_list :ci_reports_sbom_component, num_components } + source { association :ci_reports_sbom_source } + end + + after(:build) do |report, options| + options.components.each { |component| report.add_component(component) } + report.set_source(options.source) + end + + skip_create + end +end diff --git a/spec/factories/ci/reports/sbom/sources.rb b/spec/factories/ci/reports/sbom/sources.rb index 9093aba86a6..688c0250b5f 100644 --- a/spec/factories/ci/reports/sbom/sources.rb +++ b/spec/factories/ci/reports/sbom/sources.rb @@ -19,15 +19,12 @@ FactoryBot.define do } end - fingerprint { Digest::SHA256.hexdigest(data.to_json) } - skip_create initialize_with do ::Gitlab::Ci::Reports::Sbom::Source.new( type: type, - data: data, - fingerprint: fingerprint + data: data ) end end diff --git a/spec/factories/customer_relations/contacts.rb b/spec/factories/customer_relations/contacts.rb index 821c45d7514..1896510d362 100644 --- a/spec/factories/customer_relations/contacts.rb +++ b/spec/factories/customer_relations/contacts.rb @@ -11,5 +11,9 @@ FactoryBot.define do trait :with_organization do organization end + + trait :inactive do + state { :inactive } + end end end diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 403165a3935..a4f06a48621 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -26,10 +26,10 @@ FactoryBot.define do factory :wiki_page_event do action { :created } - # rubocop: disable FactoryBot/InlineAssociation + # rubocop: disable RSpec/FactoryBot/InlineAssociation # A persistent project is needed to have a wiki page being created properly. project { @overrides[:wiki_page]&.container || create(:project, :wiki_repo) } - # rubocop: enable FactoryBot/InlineAssociation + # rubocop: enable RSpec/FactoryBot/InlineAssociation target { association(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) } transient do @@ -54,6 +54,16 @@ FactoryBot.define do target { note } end + trait :for_issue do + target { association(:issue, issue_type: :issue) } + target_type { 'Issue' } + end + + trait :for_work_item do + target { association(:work_item, :task) } + target_type { 'WorkItem' } + end + factory :design_event, traits: [:has_design] do action { :created } target { design } diff --git a/spec/factories/git_wiki_commit_details.rb b/spec/factories/git_wiki_commit_details.rb deleted file mode 100644 index fb3f2954b12..00000000000 --- a/spec/factories/git_wiki_commit_details.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :git_wiki_commit_details, class: 'Gitlab::Git::Wiki::CommitDetails' do - skip_create - - transient do - author { association(:user) } - end - - sequence(:message) { |n| "Commit message #{n}" } - - initialize_with { new(author.id, author.username, author.name, author.email, message) } - end -end diff --git a/spec/factories/go_module_commits.rb b/spec/factories/go_module_commits.rb index 4f86d38954c..44f4ce9ea31 100644 --- a/spec/factories/go_module_commits.rb +++ b/spec/factories/go_module_commits.rb @@ -7,12 +7,12 @@ FactoryBot.define do transient do files { { 'foo.txt' => 'content' } } message { 'Message' } - # rubocop: disable FactoryBot/InlineAssociation + # rubocop: disable RSpec/FactoryBot/InlineAssociation # We need a persisted project so we can create commits and tags # in `commit` otherwise linting this factory with `build` strategy # will fail. project { create(:project, :repository) } - # rubocop: enable FactoryBot/InlineAssociation + # rubocop: enable RSpec/FactoryBot/InlineAssociation service do Files::MultiService.new( diff --git a/spec/factories/incident_management/timeline_event_tag_links.rb b/spec/factories/incident_management/timeline_event_tag_links.rb new file mode 100644 index 00000000000..883aca29f99 --- /dev/null +++ b/spec/factories/incident_management/timeline_event_tag_links.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :incident_management_timeline_event_tag_link, class: 'IncidentManagement::TimelineEventTagLink' do + association :timeline_event_tag, factory: :incident_management_timeline_event_tag + association :timeline_event, factory: :incident_management_timeline_event + end +end diff --git a/spec/factories/incident_management/timeline_event_tags.rb b/spec/factories/incident_management/timeline_event_tags.rb new file mode 100644 index 00000000000..6333872ee4f --- /dev/null +++ b/spec/factories/incident_management/timeline_event_tags.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :incident_management_timeline_event_tag, class: 'IncidentManagement::TimelineEventTag' do + project + name { 'Start time' } + end +end diff --git a/spec/factories/ml/candidate_metrics.rb b/spec/factories/ml/candidate_metrics.rb new file mode 100644 index 00000000000..28e3974d39f --- /dev/null +++ b/spec/factories/ml/candidate_metrics.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ml_candidate_metrics, class: '::Ml::CandidateMetric' do + association :candidate, factory: :ml_candidates + + sequence(:name) { |n| "metric#{n}" } + value { 2.0 } + step { 1 } + tracked_at { 1234 } + end +end diff --git a/spec/factories/ml/candidate_params.rb b/spec/factories/ml/candidate_params.rb new file mode 100644 index 00000000000..73cb0c54089 --- /dev/null +++ b/spec/factories/ml/candidate_params.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ml_candidate_params, class: '::Ml::CandidateParam' do + association :candidate, factory: :ml_candidates + + sequence(:name) { |n| "metric#{n}" } + sequence(:value) { |n| "value#{n}" } + end +end diff --git a/spec/factories/ml/candidates.rb b/spec/factories/ml/candidates.rb index b5644ee3841..4fbcdc46103 100644 --- a/spec/factories/ml/candidates.rb +++ b/spec/factories/ml/candidates.rb @@ -3,5 +3,12 @@ FactoryBot.define do factory :ml_candidates, class: '::Ml::Candidate' do association :experiment, factory: :ml_experiments association :user + + trait :with_metrics_and_params do + after(:create) do |candidate| + candidate.metrics = FactoryBot.create_list(:ml_candidate_metrics, 2, candidate: candidate ) + candidate.params = FactoryBot.create_list(:ml_candidate_params, 2, candidate: candidate ) + end + end end end diff --git a/spec/factories/ml/experiments.rb b/spec/factories/ml/experiments.rb index 043ca712e60..e4f5a0da6cf 100644 --- a/spec/factories/ml/experiments.rb +++ b/spec/factories/ml/experiments.rb @@ -2,7 +2,8 @@ FactoryBot.define do factory :ml_experiments, class: '::Ml::Experiment' do sequence(:name) { |n| "experiment#{n}" } - association :project - association :user + + project + user end end diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index 2159f5b2dc1..530b4616765 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -184,7 +184,7 @@ FactoryBot.define do end trait :with_pdf_attachment do - attachment { fixture_file_upload("spec/fixtures/git-cheat-sheet.pdf", "application/pdf") } + attachment { fixture_file_upload("spec/fixtures/sample.pdf", "application/pdf") } end trait :confidential do diff --git a/spec/factories/packages/packages.rb b/spec/factories/packages/packages.rb index 8074e505243..1da4f0cedbc 100644 --- a/spec/factories/packages/packages.rb +++ b/spec/factories/packages/packages.rb @@ -253,7 +253,7 @@ FactoryBot.define do end trait(:without_loaded_metadatum) do - conan_metadatum { build(:conan_metadatum, package: nil) } # rubocop:disable FactoryBot/InlineAssociation + conan_metadatum { build(:conan_metadatum, package: nil) } # rubocop:disable RSpec/FactoryBot/InlineAssociation end end diff --git a/spec/factories/packages/rpm/rpm_repository_files.rb b/spec/factories/packages/rpm/rpm_repository_files.rb new file mode 100644 index 00000000000..079d32b3995 --- /dev/null +++ b/spec/factories/packages/rpm/rpm_repository_files.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :rpm_repository_file, class: 'Packages::Rpm::RepositoryFile' do + project + + file_name { 'repomd.xml' } + file_sha1 { 'efae869b4e95d54796a46481f3a211d6a88d0323' } + file_md5 { 'ddf8a75330c896a8d7709e75f8b5982a' } + size { 3127.kilobytes } + status { :default } + + transient do + file_metadatum_trait { :xml } + end + + transient do + file_fixture { 'spec/fixtures/packages/rpm/repodata/repomd.xml' } + end + + after(:build) do |package_file, evaluator| + package_file.file = fixture_file_upload(evaluator.file_fixture) + end + + trait(:object_storage) do + file_store { Packages::Rpm::RepositoryFileUploader::Store::REMOTE } + end + + trait :pending_destruction do + status { :pending_destruction } + end + end +end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 93ed68a4573..b62995dce42 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -54,7 +54,8 @@ FactoryBot.define do import_last_error { nil } forward_deployment_enabled { nil } restrict_user_defined_variables { nil } - ci_job_token_scope_enabled { nil } + ci_outbound_job_token_scope_enabled { nil } + ci_inbound_job_token_scope_enabled { nil } runner_token_expiration_interval { nil } runner_token_expiration_interval_human_readable { nil } end @@ -112,7 +113,8 @@ FactoryBot.define do project.merge_trains_enabled = evaluator.merge_trains_enabled unless evaluator.merge_trains_enabled.nil? project.keep_latest_artifact = evaluator.keep_latest_artifact unless evaluator.keep_latest_artifact.nil? project.restrict_user_defined_variables = evaluator.restrict_user_defined_variables unless evaluator.restrict_user_defined_variables.nil? - project.ci_job_token_scope_enabled = evaluator.ci_job_token_scope_enabled unless evaluator.ci_job_token_scope_enabled.nil? + project.ci_outbound_job_token_scope_enabled = evaluator.ci_outbound_job_token_scope_enabled unless evaluator.ci_outbound_job_token_scope_enabled.nil? + project.ci_inbound_job_token_scope_enabled = evaluator.ci_inbound_job_token_scope_enabled unless evaluator.ci_inbound_job_token_scope_enabled.nil? project.runner_token_expiration_interval = evaluator.runner_token_expiration_interval unless evaluator.runner_token_expiration_interval.nil? project.runner_token_expiration_interval_human_readable = evaluator.runner_token_expiration_interval_human_readable unless evaluator.runner_token_expiration_interval_human_readable.nil? @@ -330,12 +332,6 @@ FactoryBot.define do repository_read_only { true } end - trait :broken_repo do - after(:create) do |project| - TestEnv.rm_storage_dir(project.repository_storage, "#{project.disk_path}.git/refs") - end - end - trait :test_repo do after :create do |project| # There are various tests that rely on there being no repository cache. @@ -427,12 +423,24 @@ FactoryBot.define do error_tracking_setting { association :project_error_tracking_setting } end + trait :with_redmine_integration do + has_external_issue_tracker { true } + + redmine_integration + end + trait :with_jira_integration do has_external_issue_tracker { true } jira_integration end + trait :with_prometheus_integration do + after :create do |project| + create(:prometheus_integration, project: project) + end + end + # Project with empty repository # # This is a case when you just created a project @@ -441,13 +449,6 @@ FactoryBot.define do empty_repo end - # Project with broken repository - # - # Project with an invalid repository state - factory :project_broken_repo, parent: :project do - broken_repo - end - factory :forked_project_with_submodules, parent: :project do path { 'forked-gitlabhq' } @@ -459,42 +460,6 @@ FactoryBot.define do end end - factory :redmine_project, parent: :project do - has_external_issue_tracker { true } - - redmine_integration - end - - factory :youtrack_project, parent: :project do - has_external_issue_tracker { true } - - youtrack_integration - end - - factory :jira_project, parent: :project do - has_external_issue_tracker { true } - - jira_integration - end - - factory :prometheus_project, parent: :project do - after :create do |project| - project.create_prometheus_integration( - active: true, - properties: { - api_url: 'https://prometheus.example.com/', - manual_configuration: true - } - ) - end - end - - factory :ewm_project, parent: :project do - has_external_issue_tracker { true } - - ewm_integration - end - factory :project_with_design, parent: :project do after(:create) do |project| issue = create(:issue, project: project) diff --git a/spec/factories/users/namespace_user_callouts.rb b/spec/factories/users/namespace_user_callouts.rb deleted file mode 100644 index fded63d0cce..00000000000 --- a/spec/factories/users/namespace_user_callouts.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :namespace_callout, class: 'Users::NamespaceCallout' do - feature_name { :invite_members_banner } - - user - namespace - end -end diff --git a/spec/factories/users/phone_number_validations.rb b/spec/factories/users/phone_number_validations.rb new file mode 100644 index 00000000000..da53dda89b4 --- /dev/null +++ b/spec/factories/users/phone_number_validations.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :phone_number_validation, class: 'Users::PhoneNumberValidation' do + user + country { 'US' } + international_dial_code { 1 } + phone_number { '555' } + end +end |