diff options
Diffstat (limited to 'spec/factories')
26 files changed, 787 insertions, 8 deletions
diff --git a/spec/factories/alert_management/alerts.rb b/spec/factories/alert_management/alerts.rb index 8724a626d77..ef511aa54b8 100644 --- a/spec/factories/alert_management/alerts.rb +++ b/spec/factories/alert_management/alerts.rb @@ -16,7 +16,9 @@ FactoryBot.define do end trait :with_issue do - issue + after(:create) do |alert| + create(:issue, alert_management_alert: alert, project: alert.project) + end end trait :with_assignee do |alert| @@ -73,10 +75,30 @@ FactoryBot.define do without_ended_at end - trait :low_severity do + trait :critical do + severity { 'critical' } + end + + trait :high do + severity { 'high' } + end + + trait :medium do + severity { 'medium' } + end + + trait :low do severity { 'low' } end + trait :info do + severity { 'info' } + end + + trait :unknown do + severity { 'unknown' } + end + trait :prometheus do monitoring_tool { Gitlab::AlertManagement::AlertParams::MONITORING_TOOLS[:prometheus] } end @@ -89,7 +111,7 @@ FactoryBot.define do with_monitoring_tool with_host with_description - low_severity + low end end end diff --git a/spec/factories/approvals.rb b/spec/factories/approvals.rb new file mode 100644 index 00000000000..91e6fa54894 --- /dev/null +++ b/spec/factories/approvals.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Read about factories at https://github.com/thoughtbot/factory_bot + +FactoryBot.define do + factory :approval do + merge_request + user + end +end diff --git a/spec/factories/background_migration_jobs.rb b/spec/factories/background_migration_jobs.rb new file mode 100644 index 00000000000..048e4f4fcf2 --- /dev/null +++ b/spec/factories/background_migration_jobs.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :background_migration_job, class: '::Gitlab::Database::BackgroundMigrationJob' do + class_name { 'TestJob' } + status { :pending } + arguments { [] } + + trait :succeeded do + status { :succeeded } + end + end +end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 9403967aa0a..b3815b53c2b 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -302,6 +302,18 @@ FactoryBot.define do end end + trait :report_results do + after(:build) do |build| + build.report_results << build(:ci_build_report_result) + 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/pipelines.rb b/spec/factories/ci/pipelines.rb index 85cdeaca12c..5bd5ab7d67a 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -65,6 +65,22 @@ FactoryBot.define do add_attribute(:protected) { true } end + trait :with_report_results do + status { :success } + + after(:build) do |pipeline, evaluator| + pipeline.builds << build(:ci_build, :report_results, pipeline: pipeline, project: pipeline.project) + 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 } diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index c49c26f06e5..46aa640780b 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -172,5 +172,13 @@ FactoryBot.define do cluster factory: %i(cluster provided_by_gcp) end end + + factory :clusters_applications_cilium, class: 'Clusters::Applications::Cilium' do + cluster factory: %i(cluster with_installed_helm provided_by_gcp) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end + end end end diff --git a/spec/factories/clusters/clusters.rb b/spec/factories/clusters/clusters.rb index 7d0aaa45e40..0daf624ae7e 100644 --- a/spec/factories/clusters/clusters.rb +++ b/spec/factories/clusters/clusters.rb @@ -101,6 +101,7 @@ FactoryBot.define do 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) + application_cilium factory: %i(clusters_applications_cilium installed) end trait :with_domain do diff --git a/spec/factories/custom_emoji.rb b/spec/factories/custom_emoji.rb new file mode 100644 index 00000000000..2d185794ac9 --- /dev/null +++ b/spec/factories/custom_emoji.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :custom_emoji, class: 'CustomEmoji' do + sequence(:name) { |n| "custom_emoji#{n}" } + namespace + file { fixture_file_upload(Rails.root.join('spec/fixtures/dk.png')) } + end +end diff --git a/spec/factories/deployments.rb b/spec/factories/deployments.rb index 42046464213..2aab9764560 100644 --- a/spec/factories/deployments.rb +++ b/spec/factories/deployments.rb @@ -7,7 +7,7 @@ FactoryBot.define do tag { false } user { nil } project { nil } - deployable { association :ci_build, environment: environment.name, project: environment.project } + deployable { association :ci_build, environment: environment.name, pipeline: association(:ci_pipeline, project: environment.project) } environment factory: :environment after(:build) do |deployment, evaluator| diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 60bb3044191..ecbda5fbfd3 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -21,7 +21,7 @@ FactoryBot.define do factory :closed_issue_event do action { :closed } - target factory: :closed_issue + target { association(:closed_issue, project: project) } end factory :wiki_page_event do diff --git a/spec/factories/go_module_commits.rb b/spec/factories/go_module_commits.rb new file mode 100644 index 00000000000..e42ef6696d1 --- /dev/null +++ b/spec/factories/go_module_commits.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :go_module_commit, class: 'Commit' do + skip_create + + transient do + files { { 'foo.txt' => 'content' } } + message { 'Message' } + project { create(:project, :repository) } + + service do + Files::MultiService.new( + project, + project.owner, + commit_message: message, + start_branch: project.repository.root_ref || 'master', + branch_name: project.repository.root_ref || 'master', + actions: files.map do |path, content| + { action: :create, file_path: path, content: content } + end + ) + end + + tag { nil } + tag_message { nil } + + commit do + r = service.execute + + raise "operation failed: #{r}" unless r[:status] == :success + + commit = project.repository.commit_by(oid: r[:result]) + + if tag + r = Tags::CreateService.new(project, project.owner).execute(tag, commit.sha, tag_message) + + raise "operation failed: #{r}" unless r[:status] == :success + end + + commit + end + end + + trait :files do + transient do + files { raise ArgumentError.new("files is required") } + message { 'Add files' } + end + end + + trait :package do + transient do + path { raise ArgumentError.new("path is required") } + message { 'Add package' } + files { { "#{path}/b.go" => "package b\nfunc Bye() { println(\"Goodbye world!\") }\n" } } + end + end + + trait :module do + transient do + name { nil } + message { 'Add module' } + host_prefix { "#{::Gitlab.config.gitlab.host}/#{project.path_with_namespace}" } + + url { name ? "#{host_prefix}/#{name}" : host_prefix } + path { name.to_s + '/' } + + files do + { + "#{path}go.mod" => "module #{url}\n", + "#{path}a.go" => "package a\nfunc Hi() { println(\"Hello world!\") }\n" + } + end + end + end + + initialize_with do + commit + end + end +end diff --git a/spec/factories/go_module_versions.rb b/spec/factories/go_module_versions.rb new file mode 100644 index 00000000000..b0a96197350 --- /dev/null +++ b/spec/factories/go_module_versions.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :go_module_version, class: 'Packages::Go::ModuleVersion' do + skip_create + + initialize_with do + p = attributes[:params] + s = Packages::SemVer.parse(p.semver, prefixed: true) + + raise ArgumentError.new("invalid sematic version: '#{p.semver}''") if !s && p.semver + + new(p.mod, p.type, p.commit, name: p.name, semver: s, ref: p.ref) + end + + mod { create :go_module } + type { :commit } + commit { mod.project.repository.head_commit } + name { nil } + semver { nil } + ref { nil } + + params { OpenStruct.new(mod: mod, type: type, commit: commit, name: name, semver: semver, ref: ref) } + + trait :tagged do + ref { mod.project.repository.find_tag(name) } + commit { ref.dereferenced_target } + name do + # This provides a sane default value, but in reality the caller should + # specify `name:` + + # Find 'latest' semver tag (does not actually use semver precedence rules) + mod.project.repository.tags + .filter { |t| Packages::SemVer.match?(t.name, prefixed: true) } + .map { |t| Packages::SemVer.parse(t.name, prefixed: true) } + .max { |a, b| "#{a}" <=> "#{b}" } + .to_s + end + + params { OpenStruct.new(mod: mod, type: :ref, commit: commit, semver: name, ref: ref) } + end + + trait :pseudo do + transient do + prefix do + # This provides a sane default value, but in reality the caller should + # specify `prefix:` + + # This does not take into account that `commit` may be before the + # latest tag. + + # Find 'latest' semver tag (does not actually use semver precedence rules) + v = mod.project.repository.tags + .filter { |t| Packages::SemVer.match?(t.name, prefixed: true) } + .map { |t| Packages::SemVer.parse(t.name, prefixed: true) } + .max { |a, b| "#{a}" <=> "#{b}" } + + # Default if no semver tags exist + next 'v0.0.0' unless v + + # Valid pseudo-versions are: + # vX.0.0-yyyymmddhhmmss-sha1337beef0, when no earlier tagged commit exists for X + # vX.Y.Z-pre.0.yyyymmddhhmmss-sha1337beef0, when most recent prior tag is vX.Y.Z-pre + # vX.Y.(Z+1)-0.yyyymmddhhmmss-sha1337beef0, when most recent prior tag is vX.Y.Z + + v = v.with(patch: v.patch + 1) unless v.prerelease + "#{v}.0" + end + end + + type { :pseudo } + name { "#{prefix}#{commit.committed_date.strftime('%Y%m%d%H%M%S')}-#{commit.sha[0..11]}" } + + params { OpenStruct.new(mod: mod, type: :pseudo, commit: commit, name: name, semver: name) } + end + end +end diff --git a/spec/factories/go_modules.rb b/spec/factories/go_modules.rb new file mode 100644 index 00000000000..fdbacf48d3b --- /dev/null +++ b/spec/factories/go_modules.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :go_module, class: 'Packages::Go::Module' do + initialize_with { new(attributes[:project], attributes[:name], attributes[:path]) } + skip_create + + project { create :project, :repository } + + path { '' } + name { "#{Settings.build_gitlab_go_url}/#{project.full_path}#{path.empty? ? '' : '/'}#{path}" } + end +end diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb index d51c437f83a..60d427dde00 100644 --- a/spec/factories/groups.rb +++ b/spec/factories/groups.rb @@ -51,5 +51,13 @@ FactoryBot.define do trait :owner_subgroup_creation_only do subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS } end + + trait :shared_runners_disabled do + shared_runners_enabled { false } + end + + trait :allow_descendants_override_disabled_shared_runners do + allow_descendants_override_disabled_shared_runners { true } + end end end diff --git a/spec/factories/namespaces.rb b/spec/factories/namespaces.rb index 09dbe16ef9e..f4d5848e878 100644 --- a/spec/factories/namespaces.rb +++ b/spec/factories/namespaces.rb @@ -29,5 +29,35 @@ FactoryBot.define do trait :with_root_storage_statistics do association :root_storage_statistics, factory: :namespace_root_storage_statistics end + + # Construct a hierarchy underneath the namespace. + # Each namespace will have `children` amount of children, + # and `depth` levels of descendants. + trait :with_hierarchy do + transient do + children { 4 } + depth { 4 } + end + + after(:create) do |namespace, evaluator| + def create_graph(parent: nil, children: 4, depth: 4) + return unless depth > 1 + + children.times do + factory_name = parent.model_name.singular + child = FactoryBot.create(factory_name, parent: parent) + create_graph(parent: child, children: children, depth: depth - 1) + end + + parent + end + + create_graph( + parent: namespace, + children: evaluator.children, + depth: evaluator.depth + ) + end + end end end diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index 52e91f31ec1..4b1f3194ce5 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -159,6 +159,11 @@ FactoryBot.define do system { true } end + trait :with_system_note_metadata do + system + system_note_metadata + end + trait :downvote do note { "thumbsdown" } end diff --git a/spec/factories/packages.rb b/spec/factories/packages.rb new file mode 100644 index 00000000000..562269a67bc --- /dev/null +++ b/spec/factories/packages.rb @@ -0,0 +1,355 @@ +# frozen_string_literal: true +FactoryBot.define do + factory :package, class: 'Packages::Package' do + project + name { 'my/company/app/my-app' } + sequence(:version) { |n| "1.#{n}-SNAPSHOT" } + package_type { :maven } + + factory :maven_package do + maven_metadatum + + after :build do |package| + package.maven_metadatum.path = "#{package.name}/#{package.version}" + end + + after :create do |package| + create :package_file, :xml, package: package + create :package_file, :jar, package: package + create :package_file, :pom, package: package + end + end + + factory :npm_package do + sequence(:name) { |n| "@#{project.root_namespace.path}/package-#{n}"} + version { '1.0.0' } + package_type { :npm } + + after :create do |package| + create :package_file, :npm, package: package + end + + trait :with_build do + after :create do |package| + user = package.project.creator + pipeline = create(:ci_pipeline, user: user) + create(:ci_build, user: user, pipeline: pipeline) + create :package_build_info, package: package, pipeline: pipeline + end + end + end + + factory :nuget_package do + sequence(:name) { |n| "NugetPackage#{n}"} + sequence(:version) { |n| "1.0.#{n}" } + package_type { :nuget } + + after :create do |package| + create :package_file, :nuget, package: package, file_name: "#{package.name}.#{package.version}.nupkg" + end + + trait(:with_metadatum) do + after :build do |pkg| + pkg.nuget_metadatum = build(:nuget_metadatum) + end + end + end + + factory :pypi_package do + pypi_metadatum + + sequence(:name) { |n| "pypi-package-#{n}"} + sequence(:version) { |n| "1.0.#{n}" } + package_type { :pypi } + + after :create do |package| + create :package_file, :pypi, package: package, file_name: "#{package.name}-#{package.version}.tar.gz" + end + end + + factory :composer_package do + sequence(:name) { |n| "composer-package-#{n}"} + sequence(:version) { |n| "1.0.#{n}" } + package_type { :composer } + + transient do + sha { project.repository.find_branch('master').target } + json { { name: name, version: version } } + end + + trait(:with_metadatum) do + after :create do |package, evaluator| + create :composer_metadatum, package: package, target_sha: evaluator.sha, composer_json: evaluator.json + end + end + end + + factory :conan_package do + conan_metadatum + + transient do + without_package_files { false } + end + + after :build do |package| + package.conan_metadatum.package_username = Packages::Conan::Metadatum.package_username_from( + full_path: package.project.full_path + ) + end + + sequence(:name) { |n| "package-#{n}" } + version { '1.0.0' } + package_type { :conan } + + after :create do |package, evaluator| + unless evaluator.without_package_files + create :conan_package_file, :conan_recipe_file, package: package + create :conan_package_file, :conan_recipe_manifest, package: package + create :conan_package_file, :conan_package_info, package: package + create :conan_package_file, :conan_package_manifest, package: package + create :conan_package_file, :conan_package, package: package + end + end + + trait(:without_loaded_metadatum) do + conan_metadatum { build(:conan_metadatum, package: nil) } + end + end + end + + factory :composer_metadatum, class: 'Packages::Composer::Metadatum' do + package { create(:composer_package) } + + target_sha { '123' } + composer_json { { name: 'foo' } } + end + + factory :package_build_info, class: 'Packages::BuildInfo' do + package + end + + factory :package_file, class: 'Packages::PackageFile' do + package + + file_name { 'somefile.txt' } + + transient do + file_fixture { 'spec/fixtures/packages/conan/recipe_files/conanfile.py' } + end + + after(:build) do |package_file, evaluator| + package_file.file = fixture_file_upload(evaluator.file_fixture) + end + + factory :conan_package_file do + package { create(:conan_package, without_package_files: true) } + + transient do + without_loaded_metadatum { false } + end + + trait(:conan_recipe_file) do + after :create do |package_file, evaluator| + unless evaluator.without_loaded_metadatum + create :conan_file_metadatum, :recipe_file, package_file: package_file + end + end + + file_fixture { 'spec/fixtures/packages/conan/recipe_files/conanfile.py' } + file_name { 'conanfile.py' } + file_sha1 { 'be93151dc23ac34a82752444556fe79b32c7a1ad' } + file_md5 { '12345abcde' } + size { 400.kilobytes } + end + + trait(:conan_recipe_manifest) do + after :create do |package_file, evaluator| + unless evaluator.without_loaded_metadatum + create :conan_file_metadatum, :recipe_file, package_file: package_file + end + end + + file_fixture { 'spec/fixtures/packages/conan/recipe_files/conanmanifest.txt' } + file_name { 'conanmanifest.txt' } + file_sha1 { 'be93151dc23ac34a82752444556fe79b32c7a1ad' } + file_md5 { '12345abcde' } + size { 400.kilobytes } + end + + trait(:conan_package_manifest) do + after :create do |package_file, evaluator| + unless evaluator.without_loaded_metadatum + create :conan_file_metadatum, :package_file, package_file: package_file + end + end + + file_fixture { 'spec/fixtures/packages/conan/package_files/conanmanifest.txt' } + file_name { 'conanmanifest.txt' } + file_sha1 { 'be93151dc23ac34a82752444556fe79b32c7a1ad' } + file_md5 { '12345abcde' } + size { 400.kilobytes } + end + + trait(:conan_package_info) do + after :create do |package_file, evaluator| + unless evaluator.without_loaded_metadatum + create :conan_file_metadatum, :package_file, package_file: package_file + end + end + + file_fixture { 'spec/fixtures/packages/conan/package_files/conaninfo.txt' } + file_name { 'conaninfo.txt' } + file_sha1 { 'be93151dc23ac34a82752444556fe79b32c7a1ad' } + file_md5 { '12345abcde' } + size { 400.kilobytes } + end + + trait(:conan_package) do + after :create do |package_file, evaluator| + unless evaluator.without_loaded_metadatum + create :conan_file_metadatum, :package_file, package_file: package_file + end + end + + file_fixture { 'spec/fixtures/packages/conan/package_files/conan_package.tgz' } + file_name { 'conan_package.tgz' } + file_sha1 { 'be93151dc23ac34a82752444556fe79b32c7a1ad' } + file_md5 { '12345abcde' } + size { 400.kilobytes } + end + end + + trait(:jar) do + file_fixture { 'spec/fixtures/packages/maven/my-app-1.0-20180724.124855-1.jar' } + file_name { 'my-app-1.0-20180724.124855-1.jar' } + file_sha1 { '4f0bfa298744d505383fbb57c554d4f5c12d88b3' } + size { 100.kilobytes } + end + + trait(:pom) do + file_fixture { 'spec/fixtures/packages/maven/my-app-1.0-20180724.124855-1.pom' } + file_name { 'my-app-1.0-20180724.124855-1.pom' } + file_sha1 { '19c975abd49e5102ca6c74a619f21e0cf0351c57' } + size { 200.kilobytes } + end + + trait(:xml) do + file_fixture { 'spec/fixtures/packages/maven/maven-metadata.xml' } + file_name { 'maven-metadata.xml' } + file_sha1 { '42b1bdc80de64953b6876f5a8c644f20204011b0' } + size { 300.kilobytes } + end + + trait(:npm) do + file_fixture { 'spec/fixtures/packages/npm/foo-1.0.1.tgz' } + file_name { 'foo-1.0.1.tgz' } + file_sha1 { 'be93151dc23ac34a82752444556fe79b32c7a1ad' } + verified_at { Date.current } + verification_checksum { '4437b5775e61455588a7e5187a2e5c58c680694260bbe5501c235ec690d17f83' } + size { 400.kilobytes } + end + + trait(:nuget) do + package + file_fixture { 'spec/fixtures/packages/nuget/package.nupkg' } + file_name { 'package.nupkg' } + file_sha1 { '5fe852b2a6abd96c22c11fa1ff2fb19d9ce58b57' } + size { 300.kilobytes } + end + + trait(:pypi) do + package + file_fixture { 'spec/fixtures/packages/pypi/sample-project.tar.gz' } + file_name { 'sample-project-1.0.0.tar.gz' } + file_sha1 { '2c0cfbed075d3fae226f051f0cc771b533e01aff' } + file_md5 { '0a7392d24f42f83068fa3767c5310052' } + file_sha256 { '440e5e148a25331bbd7991575f7d54933c0ebf6cc735a18ee5066ac1381bb590' } + size { 1149.bytes } + end + + trait(:object_storage) do + file_store { Packages::PackageFileUploader::Store::REMOTE } + end + + trait(:checksummed) do + verification_checksum { 'abc' } + end + + trait(:checksum_failure) do + verification_failure { 'Could not calculate the checksum' } + end + + factory :package_file_with_file, traits: [:jar] + end + + factory :maven_metadatum, class: 'Packages::Maven::Metadatum' do + association :package, package_type: :maven + path { 'my/company/app/my-app/1.0-SNAPSHOT' } + app_group { 'my.company.app' } + app_name { 'my-app' } + app_version { '1.0-SNAPSHOT' } + end + + factory :conan_metadatum, class: 'Packages::Conan::Metadatum' do + association :package, factory: [:conan_package, :without_loaded_metadatum], without_package_files: true + package_username { 'username' } + package_channel { 'stable' } + end + + factory :pypi_metadatum, class: 'Packages::Pypi::Metadatum' do + association :package, package_type: :pypi + required_python { '>=2.7' } + end + + factory :nuget_metadatum, class: 'Packages::Nuget::Metadatum' do + package { create(:nuget_package) } + + license_url { 'http://www.gitlab.com' } + project_url { 'http://www.gitlab.com' } + icon_url { 'http://www.gitlab.com' } + end + + factory :conan_file_metadatum, class: 'Packages::Conan::FileMetadatum' do + package_file { create(:conan_package_file, :conan_recipe_file, without_loaded_metadatum: true) } + recipe_revision { '0' } + conan_file_type { 'recipe_file' } + + trait(:recipe_file) do + conan_file_type { 'recipe_file' } + end + + trait(:package_file) do + package_file { create(:conan_package_file, :conan_package, without_loaded_metadatum: true) } + conan_file_type { 'package_file' } + package_revision { '0' } + conan_package_reference { '123456789' } + end + end + + factory :packages_dependency, class: 'Packages::Dependency' do + sequence(:name) { |n| "@test/package-#{n}"} + sequence(:version_pattern) { |n| "~6.2.#{n}" } + end + + factory :packages_dependency_link, class: 'Packages::DependencyLink' do + package { create(:nuget_package) } + dependency { create(:packages_dependency) } + dependency_type { :dependencies } + + trait(:with_nuget_metadatum) do + after :build do |link| + link.nuget_metadatum = build(:nuget_dependency_link_metadatum) + end + end + end + + factory :nuget_dependency_link_metadatum, class: 'Packages::Nuget::DependencyLinkMetadatum' do + dependency_link { create(:packages_dependency_link) } + target_framework { '.NETStandard2.0' } + end + + factory :packages_tag, class: 'Packages::Tag' do + package + sequence(:name) { |n| "tag-#{n}"} + end +end diff --git a/spec/factories/product_analytics_event.rb b/spec/factories/product_analytics_event.rb new file mode 100644 index 00000000000..168b255f6ca --- /dev/null +++ b/spec/factories/product_analytics_event.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :product_analytics_event do + project + platform { 'web' } + collector_tstamp { DateTime.now } + dvce_created_tstamp { DateTime.now } + event_id { SecureRandom.uuid } + name_tracker { 'sp' } + v_tracker { 'js-2.14.0' } + v_collector { 'GitLab 13.1.0-pre' } + v_etl { 'GitLab 13.1.0-pre' } + domain_userid { SecureRandom.uuid } + domain_sessionidx { 4 } + page_url { 'http://localhost:3333/products/123' } + br_lang { 'en-US' } + br_cookies { true } + br_colordepth { '24' } + os_timezone { 'America/Los_Angeles' } + doc_charset { 'UTF-8' } + domain_sessionid { SecureRandom.uuid } + end +end diff --git a/spec/factories/project_repository_storage_moves.rb b/spec/factories/project_repository_storage_moves.rb index b35d5e1d535..ea0b34e0338 100644 --- a/spec/factories/project_repository_storage_moves.rb +++ b/spec/factories/project_repository_storage_moves.rb @@ -14,5 +14,13 @@ FactoryBot.define do trait :started do state { ProjectRepositoryStorageMove.state_machines[:state].states[:started].value } end + + trait :finished do + state { ProjectRepositoryStorageMove.state_machines[:state].states[:finished].value } + end + + trait :failed do + state { ProjectRepositoryStorageMove.state_machines[:state].states[:failed].value } + end end end diff --git a/spec/factories/project_statistics.rb b/spec/factories/project_statistics.rb index f084d9d5cbf..78e80a92b3a 100644 --- a/spec/factories/project_statistics.rb +++ b/spec/factories/project_statistics.rb @@ -21,6 +21,7 @@ FactoryBot.define do project_statistics.lfs_objects_size = evaluator.size_multiplier * 3 project_statistics.build_artifacts_size = evaluator.size_multiplier * 4 project_statistics.packages_size = evaluator.size_multiplier * 5 + project_statistics.snippets_size = evaluator.size_multiplier * 6 end end end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 4affab295b8..e4b53186ea8 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -181,6 +181,7 @@ FactoryBot.define do transient do create_templates { nil } + create_branch { nil } end after :create do |project, evaluator| @@ -206,6 +207,16 @@ FactoryBot.define do message: 'test 2', branch_name: 'master') end + + if evaluator.create_branch + project.repository.create_file( + project.creator, + 'README.md', + "README on branch #{evaluator.create_branch}", + message: 'Add README.md', + branch_name: evaluator.create_branch) + + end end end @@ -305,6 +316,14 @@ FactoryBot.define do end end + trait :service_desk_disabled do + service_desk_enabled { nil } + end + + trait(:service_desk_enabled) do + service_desk_enabled { true } + end + # Project with empty repository # # This is a case when you just created a project @@ -363,4 +382,11 @@ FactoryBot.define do ) end end + + factory :project_with_design, parent: :project do + after(:create) do |project| + issue = create(:issue, project: project) + create(:design, project: project, issue: issue) + end + end end diff --git a/spec/factories/service_desk_settings.rb b/spec/factories/service_desk_settings.rb new file mode 100644 index 00000000000..abdbc5f1ea0 --- /dev/null +++ b/spec/factories/service_desk_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :service_desk_setting do + project + end +end diff --git a/spec/factories/services.rb b/spec/factories/services.rb index fd97f6abb85..9a521336fee 100644 --- a/spec/factories/services.rb +++ b/spec/factories/services.rb @@ -77,18 +77,27 @@ FactoryBot.define do username { 'jira_username' } password { 'jira_password' } jira_issue_transition_id { '56-1' } + issues_enabled { false } + project_key { nil } end after(:build) do |service, evaluator| if evaluator.create_data create(:jira_tracker_data, service: service, url: evaluator.url, api_url: evaluator.api_url, jira_issue_transition_id: evaluator.jira_issue_transition_id, - username: evaluator.username, password: evaluator.password + username: evaluator.username, password: evaluator.password, issues_enabled: evaluator.issues_enabled, + project_key: evaluator.project_key ) end end end + factory :confluence_service do + project + active { true } + confluence_url { 'https://example.atlassian.net/wiki' } + end + factory :bugzilla_service do project active { true } diff --git a/spec/factories/snippet_statistics.rb b/spec/factories/snippet_statistics.rb new file mode 100644 index 00000000000..ab2d9525466 --- /dev/null +++ b/spec/factories/snippet_statistics.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :snippet_statistics do + snippet + + initialize_with do + # statistics are automatically created when a snippet is created + snippet&.statistics || new + end + + transient do + with_data { false } + size_multiplier { 1 } + end + + after(:build) do |snippet_statistics, evaluator| + if evaluator.with_data + snippet_statistics.repository_size = evaluator.size_multiplier + snippet_statistics.commit_count = evaluator.size_multiplier * 2 + snippet_statistics.file_count = evaluator.size_multiplier * 3 + end + end + end +end diff --git a/spec/factories/terraform/state.rb b/spec/factories/terraform/state.rb index 74950ccf93e..46784581180 100644 --- a/spec/factories/terraform/state.rb +++ b/spec/factories/terraform/state.rb @@ -9,5 +9,11 @@ FactoryBot.define do trait :with_file do file { fixture_file_upload('spec/fixtures/terraform/terraform.tfstate', 'application/json') } end + + trait :locked do + sequence(:lock_xid) { |n| "lock-#{n}" } + locked_at { Time.current } + locked_by_user { create(:user) } + end end end diff --git a/spec/factories/usage_data.rb b/spec/factories/usage_data.rb index c0c5b1103fe..518b5b5e76a 100644 --- a/spec/factories/usage_data.rb +++ b/spec/factories/usage_data.rb @@ -5,7 +5,8 @@ FactoryBot.define do skip_create # non-model factories (i.e. without #save) initialize_with do - projects = create_list(:project, 4) + projects = create_list(:project, 3) + projects << create(:project, :repository) create(:board, project: projects[0]) create(:jira_service, project: projects[0]) create(:jira_service, :without_properties_callback, project: projects[1]) @@ -46,7 +47,7 @@ FactoryBot.define do create(:sentry_issue, issue: projects[0].issues[0]) # Incident Labeled Issues - incident_label_attrs = IncidentManagement::CreateIssueService::INCIDENT_LABEL + incident_label_attrs = IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES incident_label = create(:label, project: projects[0], **incident_label_attrs) create(:labeled_issue, project: projects[0], labels: [incident_label]) incident_group = create(:group) @@ -83,12 +84,23 @@ FactoryBot.define do create(:clusters_applications_knative, :installed, cluster: gcp_cluster) create(:clusters_applications_elastic_stack, :installed, cluster: gcp_cluster) create(:clusters_applications_jupyter, :installed, cluster: gcp_cluster) + create(:clusters_applications_cilium, :installed, cluster: gcp_cluster) create(:grafana_integration, project: projects[0], enabled: true) create(:grafana_integration, project: projects[1], enabled: true) create(:grafana_integration, project: projects[2], enabled: false) ProjectFeature.first.update_attribute('repository_access_level', 0) + + # Create fresh & a month (28-days SMAU) old data + env = create(:environment, project: projects[3]) + [2, 29].each do |n| + deployment_options = { created_at: n.days.ago, project: env.project, environment: env } + create(:deployment, :failed, deployment_options) + create(:deployment, :success, deployment_options) + create_list(:project_snippet, 2, project: projects[0], created_at: n.days.ago) + create(:personal_snippet, created_at: n.days.ago) + end end end end |