debian-mirror-gitlab/spec/factories/packages/packages.rb

273 lines
8.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
FactoryBot.define do
factory :package, class: 'Packages::Package' do
project
2020-11-24 15:15:51 +05:30
creator { project&.creator }
2020-07-28 23:09:34 +05:30
name { 'my/company/app/my-app' }
sequence(:version) { |n| "1.#{n}-SNAPSHOT" }
package_type { :maven }
2021-03-11 19:13:27 +05:30
status { :default }
trait :hidden do
status { :hidden }
end
trait :processing do
status { :processing }
end
2020-07-28 23:09:34 +05:30
2021-04-29 21:17:54 +05:30
trait :error do
status { :error }
end
2022-03-02 08:16:31 +05:30
trait :pending_destruction do
status { :pending_destruction }
end
2022-10-11 01:57:18 +05:30
trait :last_downloaded_at do
last_downloaded_at { 2.days.ago }
end
2020-07-28 23:09:34 +05:30
factory :maven_package do
maven_metadatum
after :build do |package|
2020-10-24 23:57:45 +05:30
package.maven_metadatum.path = package.version? ? "#{package.name}/#{package.version}" : package.name
2020-07-28 23:09:34 +05:30
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
2021-03-11 19:13:27 +05:30
factory :rubygems_package do
sequence(:name) { |n| "my_gem_#{n}" }
sequence(:version) { |n| "1.#{n}" }
package_type { :rubygems }
after :create do |package|
2021-04-29 21:17:54 +05:30
create :package_file, package.processing? ? :unprocessed_gem : :gem, package: package
create :package_file, :gemspec, package: package unless package.processing?
2021-03-11 19:13:27 +05:30
end
trait(:with_metadatum) do
after :build do |pkg|
pkg.rubygems_metadatum = build(:rubygems_metadatum)
end
end
end
2022-10-11 01:57:18 +05:30
factory :rpm_package do
sequence(:name) { |n| "package-#{n}" }
sequence(:version) { |n| "v1.0.#{n}" }
package_type { :rpm }
end
2021-01-03 14:25:43 +05:30
factory :debian_package do
2021-02-22 17:27:13 +05:30
sequence(:name) { |n| "package-#{n}" }
sequence(:version) { |n| "1.0-#{n}" }
2021-01-03 14:25:43 +05:30
package_type { :debian }
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
transient do
without_package_files { false }
file_metadatum_trait { :keep }
2021-03-11 19:13:27 +05:30
published_in { :create }
end
after :build do |package, evaluator|
if evaluator.published_in == :create
create(:debian_publication, package: package)
elsif !evaluator.published_in.nil?
create(:debian_publication, package: package, distribution: evaluator.published_in)
end
2021-03-08 18:12:59 +05:30
end
after :create do |package, evaluator|
unless evaluator.without_package_files
create :debian_package_file, :source, evaluator.file_metadatum_trait, package: package
create :debian_package_file, :dsc, evaluator.file_metadatum_trait, package: package
create :debian_package_file, :deb, evaluator.file_metadatum_trait, package: package
2021-09-04 01:27:46 +05:30
create :debian_package_file, :deb_dev, evaluator.file_metadatum_trait, package: package
2021-03-08 18:12:59 +05:30
create :debian_package_file, :udeb, evaluator.file_metadatum_trait, package: package
create :debian_package_file, :buildinfo, evaluator.file_metadatum_trait, package: package
create :debian_package_file, :changes, evaluator.file_metadatum_trait, package: package
end
end
2021-02-22 17:27:13 +05:30
factory :debian_incoming do
name { 'incoming' }
version { nil }
2021-03-08 18:12:59 +05:30
transient do
without_package_files { false }
file_metadatum_trait { :unknown }
2021-03-11 19:13:27 +05:30
published_in { nil }
2021-03-08 18:12:59 +05:30
end
2021-02-22 17:27:13 +05:30
end
2021-01-03 14:25:43 +05:30
end
2021-06-08 01:23:25 +05:30
factory :helm_package do
sequence(:name) { |n| "package-#{n}" }
sequence(:version) { |n| "v1.0.#{n}" }
package_type { :helm }
transient do
without_package_files { false }
end
after :create do |package, evaluator|
unless evaluator.without_package_files
create :helm_package_file, package: package
end
end
end
2020-07-28 23:09:34 +05:30
factory :npm_package do
2022-10-11 01:57:18 +05:30
sequence(:name) { |n| "@#{project.root_namespace.path}/package-#{n}" }
2021-11-11 11:23:49 +05:30
sequence(:version) { |n| "1.0.#{n}" }
2020-07-28 23:09:34 +05:30
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
2021-06-08 01:23:25 +05:30
factory :terraform_module_package do
sequence(:name) { |n| "module-#{n}/system" }
version { '1.0.0' }
package_type { :terraform_module }
after :create do |package|
create :package_file, :terraform_module, 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
2020-07-28 23:09:34 +05:30
factory :nuget_package do
2022-10-11 01:57:18 +05:30
sequence(:name) { |n| "NugetPackage#{n}" }
2020-07-28 23:09:34 +05:30
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
2021-09-30 23:02:18 +05:30
trait(:with_symbol_package) do
after :create do |package|
create :package_file, :snupkg, package: package, file_name: "#{package.name}.#{package.version}.snupkg"
end
end
2020-07-28 23:09:34 +05:30
end
factory :pypi_package do
2022-10-11 01:57:18 +05:30
sequence(:name) { |n| "pypi-package-#{n}" }
2020-07-28 23:09:34 +05:30
sequence(:version) { |n| "1.0.#{n}" }
package_type { :pypi }
2020-11-24 15:15:51 +05:30
transient do
without_loaded_metadatum { false }
end
after :create do |package, evaluator|
2020-07-28 23:09:34 +05:30
create :package_file, :pypi, package: package, file_name: "#{package.name}-#{package.version}.tar.gz"
2020-11-24 15:15:51 +05:30
unless evaluator.without_loaded_metadatum
create :pypi_metadatum, package: package
end
2020-07-28 23:09:34 +05:30
end
end
factory :composer_package do
2022-10-11 01:57:18 +05:30
sequence(:name) { |n| "composer-package-#{n}" }
2020-07-28 23:09:34 +05:30
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
2021-01-03 14:25:43 +05:30
factory :golang_package do
2022-10-11 01:57:18 +05:30
sequence(:name) { |n| "golang.org/x/pkg-#{n}" }
2021-01-03 14:25:43 +05:30
sequence(:version) { |n| "v1.0.#{n}" }
package_type { :golang }
end
2020-07-28 23:09:34 +05:30
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
2022-11-25 23:54:43 +05:30
conan_metadatum { build(:conan_metadatum, package: nil) } # rubocop:disable RSpec/FactoryBot/InlineAssociation
2020-07-28 23:09:34 +05:30
end
end
2020-11-24 15:15:51 +05:30
factory :generic_package do
sequence(:name) { |n| "generic-package-#{n}" }
version { '1.0.0' }
package_type { :generic }
2022-01-26 12:08:38 +05:30
trait(:with_zip_file) do
after :create do |package|
create :package_file, :generic_zip, package: package
end
end
2020-11-24 15:15:51 +05:30
end
2020-07-28 23:09:34 +05:30
end
end