Commit 32d7a304 authored by Steve Abrams's avatar Steve Abrams

Refactor package factories

Refactor package related factories into
separate files to better organize differing
factories.
parent 137f9b68
# frozen_string_literal: true
FactoryBot.define do
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
end
# frozen_string_literal: true
FactoryBot.define do
factory :composer_metadatum, class: 'Packages::Composer::Metadatum' do
package { association(:composer_package) }
target_sha { '123' }
composer_json { { name: 'foo' } }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :conan_file_metadatum, class: 'Packages::Conan::FileMetadatum' do
package_file { association(: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 { association(:conan_package_file, :conan_package, without_loaded_metadatum: true) }
conan_file_type { 'package_file' }
package_revision { '0' }
conan_package_reference { '123456789' }
end
end
end
# frozen_string_literal: true
FactoryBot.define do
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
end
# frozen_string_literal: true
FactoryBot.define do
factory :packages_dependency, class: 'Packages::Dependency' do
sequence(:name) { |n| "@test/package-#{n}"}
sequence(:version_pattern) { |n| "~6.2.#{n}" }
trait(:rubygems) do
sequence(:name) { |n| "gem-dependency-#{n}"}
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :packages_dependency_link, class: 'Packages::DependencyLink' do
package { association(:nuget_package) }
dependency { association(:packages_dependency) }
dependency_type { :dependencies }
trait(:with_nuget_metadatum) do
after :build do |link|
link.nuget_metadatum = build(:nuget_dependency_link_metadatum)
end
end
trait(:rubygems) do
package { association(:rubygems_package) }
dependency { association(:packages_dependency, :rubygems) }
end
end
end
# frozen_string_literal: true
FactoryBot.define do
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
end
# frozen_string_literal: true
FactoryBot.define do
factory :nuget_dependency_link_metadatum, class: 'Packages::Nuget::DependencyLinkMetadatum' do
dependency_link { association(:packages_dependency_link) }
target_framework { '.NETStandard2.0' }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :nuget_metadatum, class: 'Packages::Nuget::Metadatum' do
package { association(:nuget_package) }
license_url { 'http://www.gitlab.com' }
project_url { 'http://www.gitlab.com' }
icon_url { 'http://www.gitlab.com' }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :packages_tag, class: 'Packages::Tag' do
package
sequence(:name) { |n| "tag-#{n}"}
end
end
......@@ -249,117 +249,4 @@ FactoryBot.define do
package_type { :generic }
end
end
factory :composer_metadatum, class: 'Packages::Composer::Metadatum' do
package { association(:composer_package) }
target_sha { '123' }
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' }
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
package { association(:pypi_package, without_loaded_metadatum: true) }
required_python { '>=2.7' }
end
factory :nuget_metadatum, class: 'Packages::Nuget::Metadatum' do
package { association(: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 { association(: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 { association(: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}" }
trait(:rubygems) do
sequence(:name) { |n| "gem-dependency-#{n}"}
end
end
factory :packages_dependency_link, class: 'Packages::DependencyLink' do
package { association(:nuget_package) }
dependency { association(:packages_dependency) }
dependency_type { :dependencies }
trait(:with_nuget_metadatum) do
after :build do |link|
link.nuget_metadatum = build(:nuget_dependency_link_metadatum)
end
end
trait(:rubygems) do
package { association(:rubygems_package) }
dependency { association(:packages_dependency, :rubygems) }
end
end
factory :nuget_dependency_link_metadatum, class: 'Packages::Nuget::DependencyLinkMetadatum' do
dependency_link { association(:packages_dependency_link) }
target_framework { '.NETStandard2.0' }
end
factory :packages_tag, class: 'Packages::Tag' do
package
sequence(:name) { |n| "tag-#{n}"}
end
factory :packages_build_info, class: 'Packages::BuildInfo' do
package
trait :with_pipeline do
association :pipeline, factory: [:ci_pipeline, :with_job]
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :pypi_metadatum, class: 'Packages::Pypi::Metadatum' do
package { association(:pypi_package, without_loaded_metadatum: true) }
required_python { '>=2.7' }
end
end
......@@ -1184,7 +1184,7 @@ RSpec.describe Packages::Package, type: :model do
end
context 'with an already existing build info' do
let_it_be(:build_info) { create(:packages_build_info, package: package, pipeline: pipeline) }
let_it_be(:build_info) { create(:package_build_info, package: package, pipeline: pipeline) }
it 'does not create a build info' do
expect { subject }.not_to change { ::Packages::BuildInfo.count }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment