diff options
Diffstat (limited to 'spec/factories')
-rw-r--r-- | spec/factories/ci/builds.rb | 9 | ||||
-rw-r--r-- | spec/factories/ci/job_artifacts.rb | 4 | ||||
-rw-r--r-- | spec/factories/ci/pipeline_message.rb | 9 | ||||
-rw-r--r-- | spec/factories/ci/pipelines.rb | 4 | ||||
-rw-r--r-- | spec/factories/ci/secure_files.rb | 10 | ||||
-rw-r--r-- | spec/factories/clusters/agent_tokens.rb | 4 | ||||
-rw-r--r-- | spec/factories/clusters/applications/helm.rb | 1 | ||||
-rw-r--r-- | spec/factories/dependency_proxy.rb | 8 | ||||
-rw-r--r-- | spec/factories/group/crm_settings.rb | 7 | ||||
-rw-r--r-- | spec/factories/groups.rb | 6 | ||||
-rw-r--r-- | spec/factories/incident_management/issuable_escalation_statuses.rb | 2 | ||||
-rw-r--r-- | spec/factories/integrations.rb | 2 | ||||
-rw-r--r-- | spec/factories/labels.rb | 2 | ||||
-rw-r--r-- | spec/factories/namespaces.rb | 8 | ||||
-rw-r--r-- | spec/factories/packages/package_files.rb | 6 | ||||
-rw-r--r-- | spec/factories/projects.rb | 7 | ||||
-rw-r--r-- | spec/factories/usage_data.rb | 20 | ||||
-rw-r--r-- | spec/factories/users.rb | 2 | ||||
-rw-r--r-- | spec/factories/wikis.rb | 2 | ||||
-rw-r--r-- | spec/factories/work_items/work_item_types.rb (renamed from spec/factories/work_item/work_item_types.rb) | 14 |
20 files changed, 101 insertions, 26 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index e6eaebc9b6b..011021f6320 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -338,6 +338,10 @@ FactoryBot.define do running runner factory: :ci_runner + + after(:create) do |build| + build.create_runtime_metadata! + end end trait :artifacts do @@ -596,6 +600,11 @@ FactoryBot.define do failure_reason { 13 } end + trait :deployment_rejected do + failed + failure_reason { 22 } + end + trait :with_runner_session do after(:build) do |build| build.build_runner_session(url: 'https://localhost') diff --git a/spec/factories/ci/job_artifacts.rb b/spec/factories/ci/job_artifacts.rb index 223de873a04..e6eec280ed0 100644 --- a/spec/factories/ci/job_artifacts.rb +++ b/spec/factories/ci/job_artifacts.rb @@ -10,6 +10,10 @@ FactoryBot.define do expire_at { Date.yesterday } end + trait :locked do + locked { Ci::JobArtifact.lockeds[:artifacts_locked] } + end + trait :remote_store do file_store { JobArtifactUploader::Store::REMOTE} end diff --git a/spec/factories/ci/pipeline_message.rb b/spec/factories/ci/pipeline_message.rb new file mode 100644 index 00000000000..71fac24922d --- /dev/null +++ b/spec/factories/ci/pipeline_message.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_pipeline_message, class: 'Ci::PipelineMessage' do + pipeline factory: :ci_pipeline + content { 'warning' } + severity { 1 } + end +end diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index b2c1eff6fbd..122af139985 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -87,6 +87,10 @@ FactoryBot.define do locked { Ci::Pipeline.lockeds[:unlocked] } end + trait :artifacts_locked do + locked { Ci::Pipeline.lockeds[:artifacts_locked] } + end + trait :protected do add_attribute(:protected) { true } end diff --git a/spec/factories/ci/secure_files.rb b/spec/factories/ci/secure_files.rb new file mode 100644 index 00000000000..9198ea61d14 --- /dev/null +++ b/spec/factories/ci/secure_files.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_secure_file, class: 'Ci::SecureFile' do + name { 'filename' } + file { fixture_file_upload('spec/fixtures/ci_secure_files/upload-keystore.jks', 'application/octet-stream') } + checksum { 'foo1234' } + project + end +end diff --git a/spec/factories/clusters/agent_tokens.rb b/spec/factories/clusters/agent_tokens.rb index c49d197c3cd..03f765123db 100644 --- a/spec/factories/clusters/agent_tokens.rb +++ b/spec/factories/clusters/agent_tokens.rb @@ -7,5 +7,9 @@ FactoryBot.define do token_encrypted { Gitlab::CryptoHelper.aes256_gcm_encrypt(SecureRandom.hex(50)) } sequence(:name) { |n| "agent-token-#{n}" } + + trait :revoked do + status { :revoked } + end end end diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index 29197768ec0..10fa739acc1 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -118,7 +118,6 @@ FactoryBot.define do end factory :clusters_applications_runner, class: 'Clusters::Applications::Runner' do - runner factory: %i(ci_runner) cluster factory: %i(cluster with_installed_helm provided_by_gcp) end diff --git a/spec/factories/dependency_proxy.rb b/spec/factories/dependency_proxy.rb index 836ee87e4d7..afa6c61116a 100644 --- a/spec/factories/dependency_proxy.rb +++ b/spec/factories/dependency_proxy.rb @@ -8,8 +8,8 @@ FactoryBot.define do file_name { 'a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4.gz' } status { :default } - trait :expired do - status { :expired } + trait :pending_destruction do + status { :pending_destruction } end end @@ -22,8 +22,8 @@ FactoryBot.define do content_type { 'application/vnd.docker.distribution.manifest.v2+json' } status { :default } - trait :expired do - status { :expired } + trait :pending_destruction do + status { :pending_destruction } end end end diff --git a/spec/factories/group/crm_settings.rb b/spec/factories/group/crm_settings.rb new file mode 100644 index 00000000000..06a31fd69c0 --- /dev/null +++ b/spec/factories/group/crm_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :crm_settings, class: 'Group::CrmSettings' do + group + end +end diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb index 859f381e4c1..152ae061605 100644 --- a/spec/factories/groups.rb +++ b/spec/factories/groups.rb @@ -112,5 +112,11 @@ FactoryBot.define do ) end end + + trait :crm_enabled do + after(:create) do |group| + create(:crm_settings, group: group, enabled: true) + end + end end end diff --git a/spec/factories/incident_management/issuable_escalation_statuses.rb b/spec/factories/incident_management/issuable_escalation_statuses.rb index 54d0887f386..0486e0481bf 100644 --- a/spec/factories/incident_management/issuable_escalation_statuses.rb +++ b/spec/factories/incident_management/issuable_escalation_statuses.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :incident_management_issuable_escalation_status, class: 'IncidentManagement::IssuableEscalationStatus' do - issue + association :issue, factory: :incident triggered trait :triggered do diff --git a/spec/factories/integrations.rb b/spec/factories/integrations.rb index 76415f82ed0..f3a00ac083a 100644 --- a/spec/factories/integrations.rb +++ b/spec/factories/integrations.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :integration, aliases: [:service] do + factory :integration do project type { 'Integration' } end diff --git a/spec/factories/labels.rb b/spec/factories/labels.rb index a9a9416c48b..f0cef41db69 100644 --- a/spec/factories/labels.rb +++ b/spec/factories/labels.rb @@ -42,4 +42,6 @@ FactoryBot.define do factory :group_label, traits: [:base_label] do group end + + factory :admin_label, traits: [:base_label], class: 'Label' end diff --git a/spec/factories/namespaces.rb b/spec/factories/namespaces.rb index 2b3dabc07d8..e88bb634898 100644 --- a/spec/factories/namespaces.rb +++ b/spec/factories/namespaces.rb @@ -11,6 +11,14 @@ FactoryBot.define do owner { association(:user, strategy: :build, namespace: instance, username: path) } + after(:create) do |namespace, evaluator| + # simulating ::Namespaces::ProcessSyncEventsWorker because most tests don't run Sidekiq inline + # Note: we need to get refreshed `traversal_ids` it is updated via SQL query + # in `Namespaces::Traversal::Linear#sync_traversal_ids` (see the NOTE in that method). + # We cannot use `.reload` because it cleans other on-the-fly attributes. + namespace.create_ci_namespace_mirror!(traversal_ids: Namespace.find(namespace.id).traversal_ids) unless namespace.ci_namespace_mirror + end + trait :with_aggregation_schedule do after(:create) do |namespace| create(:namespace_aggregation_schedules, namespace: namespace) diff --git a/spec/factories/packages/package_files.rb b/spec/factories/packages/package_files.rb index 845fd882beb..5eac0036b91 100644 --- a/spec/factories/packages/package_files.rb +++ b/spec/factories/packages/package_files.rb @@ -6,6 +6,8 @@ FactoryBot.define do file_name { 'somefile.txt' } + status { :default } + transient do file_fixture { 'spec/fixtures/packages/conan/recipe_files/conanfile.py' } end @@ -14,6 +16,10 @@ FactoryBot.define do package_file.file = fixture_file_upload(evaluator.file_fixture) end + trait :pending_destruction do + status { :pending_destruction } + end + factory :conan_package_file do package { association(:conan_package, without_package_files: true) } diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 981f10e8260..c345fa0c8b4 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -49,6 +49,8 @@ FactoryBot.define do forward_deployment_enabled { nil } restrict_user_defined_variables { nil } ci_job_token_scope_enabled { nil } + runner_token_expiration_interval { nil } + runner_token_expiration_interval_human_readable { nil } end after(:build) do |project, evaluator| @@ -92,6 +94,8 @@ FactoryBot.define do 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.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? if evaluator.import_status import_state = project.import_state || project.build_import_state @@ -101,6 +105,9 @@ FactoryBot.define do import_state.last_error = evaluator.import_last_error import_state.save! end + + # simulating ::Projects::ProcessSyncEventsWorker because most tests don't run Sidekiq inline + project.create_ci_project_mirror!(namespace_id: project.namespace_id) unless project.ci_project_mirror end trait :public do diff --git a/spec/factories/usage_data.rb b/spec/factories/usage_data.rb index fc1f5d71f39..f00d1f8b808 100644 --- a/spec/factories/usage_data.rb +++ b/spec/factories/usage_data.rb @@ -19,16 +19,16 @@ FactoryBot.define do create(:jira_import_state, :finished, project: projects[1], label: jira_label, imported_issues_count: 3) create(:jira_import_state, :scheduled, project: projects[1], label: jira_label) create(:prometheus_integration, project: projects[1]) - create(:service, project: projects[1], type: 'JenkinsService', active: true) - create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true) - create(:service, project: projects[1], type: 'SlackService', active: true) - create(:service, project: projects[2], type: 'SlackService', active: true) - create(:service, project: projects[2], type: 'MattermostService', active: false) - create(:service, group: group, project: nil, type: 'MattermostService', active: true) - mattermost_instance = create(:service, :instance, type: 'MattermostService', active: true) - create(:service, project: projects[1], type: 'MattermostService', active: true, inherit_from_id: mattermost_instance.id) - create(:service, group: group, project: nil, type: 'SlackService', active: true, inherit_from_id: mattermost_instance.id) - create(:service, project: projects[2], type: 'CustomIssueTrackerService', active: true) + create(:integration, project: projects[1], type: 'JenkinsService', active: true) + create(:integration, project: projects[0], type: 'SlackSlashCommandsService', active: true) + create(:integration, project: projects[1], type: 'SlackService', active: true) + create(:integration, project: projects[2], type: 'SlackService', active: true) + create(:integration, project: projects[2], type: 'MattermostService', active: false) + create(:integration, group: group, project: nil, type: 'MattermostService', active: true) + mattermost_instance = create(:integration, :instance, type: 'MattermostService', active: true) + create(:integration, project: projects[1], type: 'MattermostService', active: true, inherit_from_id: mattermost_instance.id) + create(:integration, group: group, project: nil, type: 'SlackService', active: true, inherit_from_id: mattermost_instance.id) + create(:integration, project: projects[2], type: 'CustomIssueTrackerService', active: true) create(:project_error_tracking_setting, project: projects[0]) create(:project_error_tracking_setting, project: projects[1], enabled: false) alert_bot_issues = create_list(:incident, 2, project: projects[0], author: User.alert_bot) diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 8aa9654956e..5f325717ec5 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -5,7 +5,7 @@ FactoryBot.define do email { generate(:email) } name { generate(:name) } username { generate(:username) } - password { "12345678" } + password { Gitlab::Password.test_default } role { 'software_developer' } confirmed_at { Time.now } confirmation_token { nil } diff --git a/spec/factories/wikis.rb b/spec/factories/wikis.rb index 05f6fb0de58..a357f4b448d 100644 --- a/spec/factories/wikis.rb +++ b/spec/factories/wikis.rb @@ -4,7 +4,7 @@ FactoryBot.define do factory :wiki do transient do container { association(:project) } - user { container.default_owner || association(:user) } + user { container.first_owner || association(:user) } end initialize_with { Wiki.for_container(container, user) } diff --git a/spec/factories/work_item/work_item_types.rb b/spec/factories/work_items/work_item_types.rb index 1c586aab59b..0920b36bcbd 100644 --- a/spec/factories/work_item/work_item_types.rb +++ b/spec/factories/work_items/work_item_types.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true FactoryBot.define do - factory :work_item_type, class: 'WorkItem::Type' do + factory :work_item_type, class: 'WorkItems::Type' do namespace name { generate(:work_item_type_name) } - base_type { WorkItem::Type.base_types[:issue] } + base_type { WorkItems::Type.base_types[:issue] } icon_name { 'issue-type-issue' } initialize_with do @@ -13,9 +13,9 @@ FactoryBot.define do # Expect base_types to exist on the DB if type_base_attributes.slice(:namespace, :namespace_id).compact.empty? - WorkItem::Type.find_or_initialize_by(type_base_attributes).tap { |type| type.assign_attributes(attributes) } + WorkItems::Type.find_or_initialize_by(type_base_attributes).tap { |type| type.assign_attributes(attributes) } else - WorkItem::Type.new(attributes) + WorkItems::Type.new(attributes) end end @@ -24,17 +24,17 @@ FactoryBot.define do end trait :incident do - base_type { WorkItem::Type.base_types[:incident] } + base_type { WorkItems::Type.base_types[:incident] } icon_name { 'issue-type-incident' } end trait :test_case do - base_type { WorkItem::Type.base_types[:test_case] } + base_type { WorkItems::Type.base_types[:test_case] } icon_name { 'issue-type-test-case' } end trait :requirement do - base_type { WorkItem::Type.base_types[:requirement] } + base_type { WorkItems::Type.base_types[:requirement] } icon_name { 'issue-type-requirements' } end end |