diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/factories | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/factories')
23 files changed, 229 insertions, 15 deletions
diff --git a/spec/factories/analytics/cycle_analytics/issue_stage_events.rb b/spec/factories/analytics/cycle_analytics/issue_stage_events.rb new file mode 100644 index 00000000000..8ad88152611 --- /dev/null +++ b/spec/factories/analytics/cycle_analytics/issue_stage_events.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :cycle_analytics_issue_stage_event, class: 'Analytics::CycleAnalytics::IssueStageEvent' do + sequence(:stage_event_hash_id) { |n| n } + sequence(:issue_id) { 0 } + sequence(:group_id) { 0 } + sequence(:project_id) { 0 } + + start_event_timestamp { 3.weeks.ago.to_date } + end_event_timestamp { 2.weeks.ago.to_date } + end +end diff --git a/spec/factories/analytics/cycle_analytics/merge_request_stage_events.rb b/spec/factories/analytics/cycle_analytics/merge_request_stage_events.rb new file mode 100644 index 00000000000..d8fa43b024f --- /dev/null +++ b/spec/factories/analytics/cycle_analytics/merge_request_stage_events.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :cycle_analytics_merge_request_stage_event, class: 'Analytics::CycleAnalytics::MergeRequestStageEvent' do + sequence(:stage_event_hash_id) { |n| n } + sequence(:merge_request_id) { 0 } + sequence(:group_id) { 0 } + sequence(:project_id) { 0 } + + start_event_timestamp { 3.weeks.ago.to_date } + end_event_timestamp { 2.weeks.ago.to_date } + end +end diff --git a/spec/factories/authentication_event.rb b/spec/factories/authentication_event.rb index ff539c6f5c4..e02698fac38 100644 --- a/spec/factories/authentication_event.rb +++ b/spec/factories/authentication_event.rb @@ -7,5 +7,13 @@ FactoryBot.define do user_name { 'Jane Doe' } ip_address { '127.0.0.1' } result { :failed } + + trait :successful do + result { :success } + end + + trait :failed do + result { :failed } + end end end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 1108c606df3..98023334894 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -282,6 +282,12 @@ FactoryBot.define do end end + trait :unarchived_trace_artifact do + after(:create) do |build, evaluator| + create(:ci_job_artifact, :unarchived_trace_artifact, job: build) + end + end + trait :trace_with_duplicate_sections do after(:create) do |build, evaluator| trace = File.binread( @@ -443,7 +449,7 @@ FactoryBot.define do options do { image: { name: 'ruby:2.7', entrypoint: '/bin/sh' }, - services: ['postgres', { name: 'docker:stable-dind', entrypoint: '/bin/sh', command: 'sleep 30', alias: 'docker' }], + services: ['postgres', { name: 'docker:stable-dind', entrypoint: '/bin/sh', command: 'sleep 30', alias: 'docker' }, { name: 'mysql:latest', variables: { MYSQL_ROOT_PASSWORD: 'root123.' } }], script: %w(echo), after_script: %w(ls date), artifacts: { diff --git a/spec/factories/ci/job_artifacts.rb b/spec/factories/ci/job_artifacts.rb index 2f4eb99a073..223de873a04 100644 --- a/spec/factories/ci/job_artifacts.rb +++ b/spec/factories/ci/job_artifacts.rb @@ -87,6 +87,17 @@ FactoryBot.define do end end + trait :unarchived_trace_artifact do + file_type { :trace } + file_format { :raw } + + after(:build) do |artifact, evaluator| + file = double('file', path: '/path/to/job.log') + artifact.file = file + allow(artifact.file).to receive(:file).and_return(CarrierWave::SanitizedFile.new(file)) + end + end + trait :junit do file_type { :junit } file_format { :gzip } diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index ae3404a41a2..1d25964a4be 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -213,6 +213,14 @@ FactoryBot.define do end end + trait :with_persisted_artifacts do + status { :success } + + after(:create) do |pipeline, evaluator| + pipeline.builds << create(:ci_build, :artifacts, pipeline: pipeline, project: pipeline.project) + end + end + trait :with_job do after(:build) do |pipeline, evaluator| pipeline.builds << build(:ci_build, pipeline: pipeline, project: pipeline.project) diff --git a/spec/factories/ci/reports/security/findings.rb b/spec/factories/ci/reports/security/findings.rb index e3971bc48f3..8a39fce971f 100644 --- a/spec/factories/ci/reports/security/findings.rb +++ b/spec/factories/ci/reports/security/findings.rb @@ -9,7 +9,7 @@ FactoryBot.define do metadata_version { 'sast:1.0' } name { 'Cipher with no integrity' } report_type { :sast } - raw_metadata do + original_data do { description: "The cipher does not provide data integrity update 1", solution: "GCM mode introduces an HMAC into the resulting encrypted data, providing integrity of the result.", @@ -26,7 +26,7 @@ FactoryBot.define do url: "https://crypto.stackexchange.com/questions/31428/pbewithmd5anddes-cipher-does-not-check-for-integrity-first" } ] - }.to_json + }.deep_stringify_keys end scanner factory: :ci_reports_security_scanner severity { :high } diff --git a/spec/factories/ci/runner_namespaces.rb b/spec/factories/ci/runner_namespaces.rb index a5060d196ca..e3cebed789b 100644 --- a/spec/factories/ci/runner_namespaces.rb +++ b/spec/factories/ci/runner_namespaces.rb @@ -2,7 +2,14 @@ FactoryBot.define do factory :ci_runner_namespace, class: 'Ci::RunnerNamespace' do - runner factory: [:ci_runner, :group] group + + after(:build) do |runner_namespace, evaluator| + unless runner_namespace.runner.present? + runner_namespace.runner = build( + :ci_runner, :group, runner_namespaces: [runner_namespace] + ) + end + end end end diff --git a/spec/factories/ci/runners.rb b/spec/factories/ci/runners.rb index d0853df4e4b..6665b7b76a0 100644 --- a/spec/factories/ci/runners.rb +++ b/spec/factories/ci/runners.rb @@ -11,6 +11,7 @@ FactoryBot.define do runner_type { :instance_type } transient do + groups { [] } projects { [] } end @@ -18,6 +19,10 @@ FactoryBot.define do evaluator.projects.each do |proj| runner.runner_projects << build(:ci_runner_project, project: proj) end + + evaluator.groups.each do |group| + runner.runner_namespaces << build(:ci_runner_namespace, namespace: group) + end end trait :online do @@ -32,7 +37,9 @@ FactoryBot.define do runner_type { :group_type } after(:build) do |runner, evaluator| - runner.groups << build(:group) if runner.groups.empty? + if runner.runner_namespaces.empty? + runner.runner_namespaces << build(:ci_runner_namespace) + end end end diff --git a/spec/factories/customer_relations/issue_customer_relations_contacts.rb b/spec/factories/customer_relations/issue_customer_relations_contacts.rb new file mode 100644 index 00000000000..6a4fecfb3cf --- /dev/null +++ b/spec/factories/customer_relations/issue_customer_relations_contacts.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :issue_customer_relations_contact, class: 'CustomerRelations::IssueContact' do + issue { association(:issue, project: project) } + contact { association(:contact, group: group) } + + transient do + group { association(:group) } + project { association(:project, group: group) } + end + + trait :for_contact do + issue { association(:issue, project: project) } + contact { raise ArgumentError, '`contact` is manadatory' } + + transient do + project { association(:project, group: contact.group) } + end + end + + trait :for_issue do + issue { raise ArgumentError, '`issue` is manadatory' } + contact { association(:contact, group: issue.project.group) } + end + end +end diff --git a/spec/factories/design_management/designs.rb b/spec/factories/design_management/designs.rb index c23a67fe95b..56a1b55b969 100644 --- a/spec/factories/design_management/designs.rb +++ b/spec/factories/design_management/designs.rb @@ -39,7 +39,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.main.bulk_insert(dv_table_name, [action.row_attrs(version)]) # rubocop:disable Gitlab/BulkInsert + ApplicationRecord.legacy_bulk_insert(dv_table_name, [action.row_attrs(version)]) # rubocop:disable Gitlab/BulkInsert end # always a creation diff --git a/spec/factories/error_tracking/error_event.rb b/spec/factories/error_tracking/error_event.rb index 9620e3999d6..83f38150b11 100644 --- a/spec/factories/error_tracking/error_event.rb +++ b/spec/factories/error_tracking/error_event.rb @@ -63,5 +63,9 @@ FactoryBot.define do level { 'error' } occurred_at { Time.now.iso8601 } payload { Gitlab::Json.parse(File.read(Rails.root.join('spec/fixtures/', 'error_tracking/parsed_event.json'))) } + + trait :browser do + payload { Gitlab::Json.parse(File.read(Rails.root.join('spec/fixtures/', 'error_tracking/browser_event.json'))) } + end end end diff --git a/spec/factories/gitlab/database/reindexing/queued_action.rb b/spec/factories/gitlab/database/reindexing/queued_action.rb new file mode 100644 index 00000000000..30e12a81272 --- /dev/null +++ b/spec/factories/gitlab/database/reindexing/queued_action.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :reindexing_queued_action, class: 'Gitlab::Database::Reindexing::QueuedAction' do + association :index, factory: :postgres_index + + state { Gitlab::Database::Reindexing::QueuedAction.states[:queued] } + index_identifier { index.identifier } + end +end diff --git a/spec/factories/group_members.rb b/spec/factories/group_members.rb index 37ddbc09616..ab2321c81c4 100644 --- a/spec/factories/group_members.rb +++ b/spec/factories/group_members.rb @@ -34,5 +34,18 @@ FactoryBot.define do access_level { GroupMember::MINIMAL_ACCESS } end + + transient do + tasks_to_be_done { [] } + end + + after(:build) do |group_member, evaluator| + if evaluator.tasks_to_be_done.present? + build(:member_task, + member: group_member, + project: build(:project, namespace: group_member.source), + tasks_to_be_done: evaluator.tasks_to_be_done) + end + end end end diff --git a/spec/factories/integrations.rb b/spec/factories/integrations.rb index 63f85c04ac7..76415f82ed0 100644 --- a/spec/factories/integrations.rb +++ b/spec/factories/integrations.rb @@ -111,6 +111,12 @@ FactoryBot.define do end end + factory :shimo_integration, class: 'Integrations::Shimo' do + project + active { true } + external_wiki_url { 'https://shimo.example.com/desktop' } + end + factory :confluence_integration, class: 'Integrations::Confluence' do project active { true } @@ -216,6 +222,11 @@ FactoryBot.define do template { true } end + trait :group do + group + project { nil } + end + trait :instance do project { nil } instance { true } diff --git a/spec/factories/member_tasks.rb b/spec/factories/member_tasks.rb new file mode 100644 index 00000000000..133ccce5f8a --- /dev/null +++ b/spec/factories/member_tasks.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :member_task do + member { association(:group_member, :invited) } + project { association(:project, namespace: member.source) } + tasks_to_be_done { [:ci, :code] } + end +end diff --git a/spec/factories/namespaces/project_namespaces.rb b/spec/factories/namespaces/project_namespaces.rb index ca9fc5f8768..6bf17088741 100644 --- a/spec/factories/namespaces/project_namespaces.rb +++ b/spec/factories/namespaces/project_namespaces.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :project_namespace, class: 'Namespaces::ProjectNamespace' do - project + association :project, factory: :project, strategy: :build parent { project.namespace } visibility_level { project.visibility_level } name { project.name } diff --git a/spec/factories/operations/feature_flags/strategy.rb b/spec/factories/operations/feature_flags/strategy.rb index bdb5d9f0f3c..8d04b6d25aa 100644 --- a/spec/factories/operations/feature_flags/strategy.rb +++ b/spec/factories/operations/feature_flags/strategy.rb @@ -5,5 +5,37 @@ FactoryBot.define do association :feature_flag, factory: :operations_feature_flag name { "default" } parameters { {} } + + trait :default do + name { "default" } + parameters { {} } + end + + trait :gitlab_userlist do + association :user_list, factory: :operations_feature_flag_user_list + name { "gitlabUserList" } + parameters { {} } + end + + trait :flexible_rollout do + name { "flexibleRollout" } + parameters do + { + groupId: 'default', + rollout: '10', + stickiness: 'default' + } + end + end + + trait :gradual_rollout do + name { "gradualRolloutUserId" } + parameters { { percentage: '10', groupId: 'default' } } + end + + trait :userwithid do + name { "userWithId" } + parameters { { userIds: 'user1' } } + end end end diff --git a/spec/factories/packages/helm/file_metadatum.rb b/spec/factories/packages/helm/file_metadatum.rb index 3f599b5d5c0..590956e5d49 100644 --- a/spec/factories/packages/helm/file_metadatum.rb +++ b/spec/factories/packages/helm/file_metadatum.rb @@ -9,7 +9,11 @@ FactoryBot.define do package_file { association(:helm_package_file, without_loaded_metadatum: true) } sequence(:channel) { |n| "#{FFaker::Lorem.word}-#{n}" } metadata do - { 'name': package_file.package.name, 'version': package_file.package.version, 'apiVersion': 'v2' }.tap do |defaults| + { + 'name': package_file.package.name, + 'version': package_file.package.version, + 'apiVersion': 'v2' + }.tap do |defaults| defaults['description'] = description if description end end diff --git a/spec/factories/packages/npm/metadata.rb b/spec/factories/packages/npm/metadata.rb new file mode 100644 index 00000000000..c8acaa10199 --- /dev/null +++ b/spec/factories/packages/npm/metadata.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :npm_metadatum, class: 'Packages::Npm::Metadatum' do + package { association(:npm_package) } + + package_json do + { + 'name': package.name, + 'version': package.version, + 'dist': { + 'tarball': 'http://localhost/tarball.tgz', + 'shasum': '1234567890' + } + } + end + end +end diff --git a/spec/factories/project_members.rb b/spec/factories/project_members.rb index 3e83ab7118c..f2dedc178c7 100644 --- a/spec/factories/project_members.rb +++ b/spec/factories/project_members.rb @@ -23,5 +23,15 @@ FactoryBot.define do trait :blocked do after(:build) { |project_member, _| project_member.user.block! } end + + transient do + tasks_to_be_done { [] } + end + + after(:build) do |project_member, evaluator| + if evaluator.tasks_to_be_done.present? + build(:member_task, member: project_member, project: project_member.source, tasks_to_be_done: evaluator.tasks_to_be_done) + end + end end end diff --git a/spec/factories/user_highest_roles.rb b/spec/factories/user_highest_roles.rb index 761a8b6c583..ee5794b55fb 100644 --- a/spec/factories/user_highest_roles.rb +++ b/spec/factories/user_highest_roles.rb @@ -5,10 +5,10 @@ FactoryBot.define do highest_access_level { nil } user - trait(:guest) { highest_access_level { GroupMember::GUEST } } - trait(:reporter) { highest_access_level { GroupMember::REPORTER } } - trait(:developer) { highest_access_level { GroupMember::DEVELOPER } } - trait(:maintainer) { highest_access_level { GroupMember::MAINTAINER } } - trait(:owner) { highest_access_level { GroupMember::OWNER } } + trait(:guest) { highest_access_level { GroupMember::GUEST } } + trait(:reporter) { highest_access_level { GroupMember::REPORTER } } + trait(:developer) { highest_access_level { GroupMember::DEVELOPER } } + trait(:maintainer) { highest_access_level { GroupMember::MAINTAINER } } + trait(:owner) { highest_access_level { GroupMember::OWNER } } end end diff --git a/spec/factories/users/credit_card_validations.rb b/spec/factories/users/credit_card_validations.rb index 09940347708..509e86e7bd3 100644 --- a/spec/factories/users/credit_card_validations.rb +++ b/spec/factories/users/credit_card_validations.rb @@ -3,7 +3,10 @@ FactoryBot.define do factory :credit_card_validation, class: 'Users::CreditCardValidation' do user - - credit_card_validated_at { Time.current } + sequence(:credit_card_validated_at) { |n| Time.current + n } + expiration_date { 1.year.from_now.end_of_month } + last_digits { 10 } + holder_name { 'John Smith' } + network { 'AmericanExpress' } end end |