diff options
Diffstat (limited to 'spec/factories')
-rw-r--r-- | spec/factories/audit_events.rb | 15 | ||||
-rw-r--r-- | spec/factories/ci/bridge.rb | 9 | ||||
-rw-r--r-- | spec/factories/ci/builds.rb | 6 | ||||
-rw-r--r-- | spec/factories/ci/pipeline_artifacts.rb | 33 | ||||
-rw-r--r-- | spec/factories/ci/pipelines.rb | 16 | ||||
-rw-r--r-- | spec/factories/ci/reports/codequality_degradations.rb | 98 | ||||
-rw-r--r-- | spec/factories/ci/resource.rb | 2 | ||||
-rw-r--r-- | spec/factories/dependency_proxy.rb | 3 | ||||
-rw-r--r-- | spec/factories/merge_request_diffs.rb | 6 | ||||
-rw-r--r-- | spec/factories/merge_requests.rb | 12 | ||||
-rw-r--r-- | spec/factories/packages.rb | 18 | ||||
-rw-r--r-- | spec/factories/packages/debian/group_component.rb | 9 | ||||
-rw-r--r-- | spec/factories/packages/debian/project_component.rb | 9 | ||||
-rw-r--r-- | spec/factories/token_with_ivs.rb | 9 | ||||
-rw-r--r-- | spec/factories/u2f_registrations.rb | 2 |
15 files changed, 226 insertions, 21 deletions
diff --git a/spec/factories/audit_events.rb b/spec/factories/audit_events.rb index 4e72976a9e5..05b86d2f13b 100644 --- a/spec/factories/audit_events.rb +++ b/spec/factories/audit_events.rb @@ -49,6 +49,21 @@ FactoryBot.define do end end + trait :unauthenticated do + author_id { -1 } + details do + { + custom_message: 'Custom action', + author_name: 'An unauthenticated user', + target_id: target_project.id, + target_type: 'Project', + target_details: target_project.name, + ip_address: '127.0.0.1', + entity_path: target_project.full_path + } + end + end + trait :group_event do transient { target_group { association(:group) } } diff --git a/spec/factories/ci/bridge.rb b/spec/factories/ci/bridge.rb index 7727a468633..7258b3367d3 100644 --- a/spec/factories/ci/bridge.rb +++ b/spec/factories/ci/bridge.rb @@ -53,6 +53,11 @@ FactoryBot.define do finished_at { '2013-10-29 09:53:28 CET' } end + trait :success do + finished + status { 'success' } + end + trait :failed do finished status { 'failed' } @@ -75,5 +80,9 @@ FactoryBot.define do trait :playable do manual end + + trait :allowed_to_fail do + allow_failure { true } + end end end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 24abad66530..c85918a3187 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -308,12 +308,6 @@ FactoryBot.define do end end - trait :codequality_report do - after(:build) do |build| - build.job_artifacts << create(:ci_job_artifact, :codequality, job: build) - end - end - trait :test_reports do after(:build) do |build| build.job_artifacts << create(:ci_job_artifact, :junit, job: build) diff --git a/spec/factories/ci/pipeline_artifacts.rb b/spec/factories/ci/pipeline_artifacts.rb index fa33609dd6c..05ff7afed7c 100644 --- a/spec/factories/ci/pipeline_artifacts.rb +++ b/spec/factories/ci/pipeline_artifacts.rb @@ -4,18 +4,30 @@ FactoryBot.define do factory :ci_pipeline_artifact, class: 'Ci::PipelineArtifact' do pipeline factory: :ci_pipeline project { pipeline.project } - file_type { :code_coverage } file_format { :raw } file_store { ObjectStorage::SUPPORTED_STORES.first } - size { 1.megabytes } - + size { 1.megabyte } + file_type { :code_coverage } after(:build) do |artifact, _evaluator| artifact.file = fixture_file_upload( Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage.json'), 'application/json') end - trait :with_multibyte_characters do + trait :with_coverage_report do + file_type { :code_coverage } + + after(:build) do |artifact, _evaluator| + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage.json'), 'application/json') + end + + size { file.size } + end + + trait :with_coverage_multibyte_characters do + file_type { :code_coverage } size { { "utf8" => "✓" }.to_json.bytesize } + after(:build) do |artifact, _evaluator| artifact.file = CarrierWaveStringFile.new_file( file_content: { "utf8" => "✓" }.to_json, @@ -26,12 +38,25 @@ FactoryBot.define do end trait :with_code_coverage_with_multiple_files do + file_type { :code_coverage } + after(:build) do |artifact, _evaluator| artifact.file = fixture_file_upload( Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage_with_multiple_files.json'), 'application/json' ) end + size { 1.megabyte } + end + + trait :with_codequality_mr_diff_report do + file_type { :code_quality_mr_diff } + + after(:build) do |artifact, _evaluator| + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/pipeline_artifacts/code_quality_mr_diff.json'), 'application/json') + end + size { file.size } end end diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index 86a8b008e48..530bb0cd25b 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -93,14 +93,6 @@ FactoryBot.define do end end - trait :with_codequality_report do - status { :success } - - after(:build) do |pipeline, evaluator| - pipeline.builds << build(:ci_build, :codequality_report, pipeline: pipeline, project: pipeline.project) - end - end - trait :with_test_reports do status { :success } @@ -159,7 +151,13 @@ FactoryBot.define do trait :with_coverage_report_artifact do after(:build) do |pipeline, evaluator| - pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, pipeline: pipeline, project: pipeline.project) + pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, :with_coverage_report, pipeline: pipeline, project: pipeline.project) + end + end + + trait :with_codequality_mr_diff_report do + after(:build) do |pipeline, evaluator| + pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, :with_codequality_mr_diff_report, pipeline: pipeline, project: pipeline.project) end end diff --git a/spec/factories/ci/reports/codequality_degradations.rb b/spec/factories/ci/reports/codequality_degradations.rb new file mode 100644 index 00000000000..d82157b457a --- /dev/null +++ b/spec/factories/ci/reports/codequality_degradations.rb @@ -0,0 +1,98 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :codequality_degradation_1, class: Hash do + skip_create + + initialize_with do + { + "categories": [ + "Complexity" + ], + "check_name": "argument_count", + "content": { + "body": "" + }, + "description": "Avoid parameter lists longer than 5 parameters. [12/5]", + "fingerprint": "15cdb5c53afd42bc22f8ca366a08d547", + "location": { + "path": "file_a.rb", + "lines": { + "begin": 10, + "end": 10 + } + }, + "other_locations": [], + "remediation_points": 900000, + "severity": "major", + "type": "issue", + "engine_name": "structure" + }.with_indifferent_access + end + end + + factory :codequality_degradation_2, class: Hash do + skip_create + + initialize_with do + { + "categories": [ + "Complexity" + ], + "check_name": "argument_count", + "content": { + "body": "" + }, + "description": "Method `new_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.", + "fingerprint": "f3bdc1e8c102ba5fbd9e7f6cda51c95e", + "location": { + "path": "file_a.rb", + "lines": { + "begin": 10, + "end": 10 + } + }, + "other_locations": [], + "remediation_points": 900000, + "severity": "major", + "type": "issue", + "engine_name": "structure" + }.with_indifferent_access + end + end + + factory :codequality_degradation_3, class: Hash do + skip_create + + initialize_with do + { + "type": "Issue", + "check_name": "Rubocop/Metrics/ParameterLists", + "description": "Avoid parameter lists longer than 5 parameters. [12/5]", + "categories": [ + "Complexity" + ], + "remediation_points": 550000, + "location": { + "path": "file_b.rb", + "positions": { + "begin": { + "column": 14, + "line": 10 + }, + "end": { + "column": 39, + "line": 10 + } + } + }, + "content": { + "body": "This cop checks for methods with too many parameters.\nThe maximum number of parameters is configurable.\nKeyword arguments can optionally be excluded from the total count." + }, + "engine_name": "rubocop", + "fingerprint": "ab5f8b935886b942d621399f5a2ca16e", + "severity": "minor" + }.with_indifferent_access + end + end +end diff --git a/spec/factories/ci/resource.rb b/spec/factories/ci/resource.rb index 515329506e5..dec26013a25 100644 --- a/spec/factories/ci/resource.rb +++ b/spec/factories/ci/resource.rb @@ -5,7 +5,7 @@ FactoryBot.define do resource_group factory: :ci_resource_group trait(:retained) do - build factory: :ci_build + processable factory: :ci_build end end end diff --git a/spec/factories/dependency_proxy.rb b/spec/factories/dependency_proxy.rb index de95df19876..94a7986a8fa 100644 --- a/spec/factories/dependency_proxy.rb +++ b/spec/factories/dependency_proxy.rb @@ -10,7 +10,8 @@ FactoryBot.define do factory :dependency_proxy_manifest, class: 'DependencyProxy::Manifest' do group file { fixture_file_upload('spec/fixtures/dependency_proxy/manifest') } - digest { 'sha256:5ab5a6872b264fe4fd35d63991b9b7d8425f4bc79e7cf4d563c10956581170c9' } + digest { 'sha256:d0710affa17fad5f466a70159cc458227bd25d4afb39514ef662ead3e6c99515' } file_name { 'alpine:latest.json' } + content_type { 'application/vnd.docker.distribution.manifest.v2+json' } end end diff --git a/spec/factories/merge_request_diffs.rb b/spec/factories/merge_request_diffs.rb index 481cabdae6d..f93f3f22109 100644 --- a/spec/factories/merge_request_diffs.rb +++ b/spec/factories/merge_request_diffs.rb @@ -10,12 +10,18 @@ FactoryBot.define do head_commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) } start_commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) } + diff_type { :regular } + trait :external do external_diff { fixture_file_upload("spec/fixtures/doc_sample.txt", "plain/txt") } stored_externally { true } importing { true } # this avoids setting the state to 'empty' end + trait :merge_head do + diff_type { :merge_head } + end + factory :external_merge_request_diff, traits: [:external] end end diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index e69743122cc..dba98593a03 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -200,6 +200,18 @@ FactoryBot.define do end end + trait :with_codequality_mr_diff_reports do + after(:build) do |merge_request| + merge_request.head_pipeline = build( + :ci_pipeline, + :success, + :with_codequality_mr_diff_report, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha) + end + end + trait :with_terraform_reports do after(:build) do |merge_request| merge_request.head_pipeline = build( diff --git a/spec/factories/packages.rb b/spec/factories/packages.rb index 31f1aabe5dd..ca38793ac08 100644 --- a/spec/factories/packages.rb +++ b/spec/factories/packages.rb @@ -176,6 +176,24 @@ FactoryBot.define do composer_json { { name: 'foo' } } end + factory :composer_cache_file, class: 'Packages::Composer::CacheFile' do + group + + file_sha256 { '1' * 64 } + + transient do + file_fixture { 'spec/fixtures/packages/composer/package.json' } + end + + after(:build) do |cache_file, evaluator| + cache_file.file = fixture_file_upload(evaluator.file_fixture) + end + + trait(:object_storage) do + file_store { Packages::Composer::CacheUploader::Store::REMOTE } + end + end + factory :maven_metadatum, class: 'Packages::Maven::Metadatum' do association :package, package_type: :maven path { 'my/company/app/my-app/1.0-SNAPSHOT' } diff --git a/spec/factories/packages/debian/group_component.rb b/spec/factories/packages/debian/group_component.rb new file mode 100644 index 00000000000..92d438be389 --- /dev/null +++ b/spec/factories/packages/debian/group_component.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :debian_group_component, class: 'Packages::Debian::GroupComponent' do + distribution { association(:debian_group_distribution) } + + sequence(:name) { |n| "group-component-#{n}" } + end +end diff --git a/spec/factories/packages/debian/project_component.rb b/spec/factories/packages/debian/project_component.rb new file mode 100644 index 00000000000..a56aec4cef0 --- /dev/null +++ b/spec/factories/packages/debian/project_component.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :debian_project_component, class: 'Packages::Debian::ProjectComponent' do + distribution { association(:debian_project_distribution) } + + sequence(:name) { |n| "project-component-#{n}" } + end +end diff --git a/spec/factories/token_with_ivs.rb b/spec/factories/token_with_ivs.rb new file mode 100644 index 00000000000..68989f6c5bc --- /dev/null +++ b/spec/factories/token_with_ivs.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :token_with_iv do + hashed_token { ::Digest::SHA256.digest(SecureRandom.hex(50)) } + iv { ::Digest::SHA256.digest(SecureRandom.hex(50)) } + hashed_plaintext_token { ::Digest::SHA256.digest(SecureRandom.hex(50)) } + end +end diff --git a/spec/factories/u2f_registrations.rb b/spec/factories/u2f_registrations.rb index 7017b0ee9e7..40ad221415c 100644 --- a/spec/factories/u2f_registrations.rb +++ b/spec/factories/u2f_registrations.rb @@ -2,6 +2,8 @@ FactoryBot.define do factory :u2f_registration do + user + certificate { FFaker::BaconIpsum.characters(728) } key_handle { FFaker::BaconIpsum.characters(86) } public_key { FFaker::BaconIpsum.characters(88) } |