summaryrefslogtreecommitdiff
path: root/db/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'db/fixtures')
-rw-r--r--db/fixtures/development/24_forks.rb33
-rw-r--r--db/fixtures/development/26_packages.rb159
-rw-r--r--db/fixtures/development/27_product_analytics_events.rb56
3 files changed, 238 insertions, 10 deletions
diff --git a/db/fixtures/development/24_forks.rb b/db/fixtures/development/24_forks.rb
index cb6dbb7504d..536d9f9e2ba 100644
--- a/db/fixtures/development/24_forks.rb
+++ b/db/fixtures/development/24_forks.rb
@@ -10,17 +10,30 @@ Sidekiq::Testing.inline! do
# we use randomized approach (e.g. `Array#sample`).
return unless source_project
- fork_project = Projects::ForkService.new(
- source_project,
- user,
- namespace: user.namespace,
- skip_disk_validation: true
- ).execute
+ Sidekiq::Worker.skipping_transaction_check do
+ fork_project = Projects::ForkService.new(
+ source_project,
+ user,
+ namespace: user.namespace,
+ skip_disk_validation: true
+ ).execute
- if fork_project.valid?
- print '.'
- else
- print 'F'
+ # Seed-Fu runs this entire fixture in a transaction, so the `after_commit`
+ # hook won't run until after the fixture is loaded. That is too late
+ # since the Sidekiq::Testing block has already exited. Force clearing
+ # the `after_commit` queue to ensure the job is run now.
+ fork_project.send(:_run_after_commit_queue)
+ fork_project.import_state.send(:_run_after_commit_queue)
+
+ # Expire repository cache after import to ensure
+ # valid_repo? call below returns a correct answer
+ fork_project.repository.expire_all_method_caches
+
+ if fork_project.valid? && fork_project.valid_repo?
+ print '.'
+ else
+ print 'F'
+ end
end
end
end
diff --git a/db/fixtures/development/26_packages.rb b/db/fixtures/development/26_packages.rb
new file mode 100644
index 00000000000..6096fd8962a
--- /dev/null
+++ b/db/fixtures/development/26_packages.rb
@@ -0,0 +1,159 @@
+# frozen_string_literal: true
+
+class Gitlab::Seeder::Packages
+ attr_reader :project
+
+ def initialize(project)
+ @project = project
+ end
+
+ def seed_packages(package_type)
+ send("seed_#{package_type}_packages")
+ end
+
+ def seed_npm_packages
+ 5.times do |i|
+ name = "@#{@project.root_namespace.path}/npm_package_#{SecureRandom.hex}"
+ version = "1.12.#{i}"
+
+ params = Gitlab::Json.parse(read_fixture_file('npm', 'payload.json')
+ .gsub('@root/npm-test', name)
+ .gsub('1.0.1', version))
+ .with_indifferent_access
+
+ ::Packages::Npm::CreatePackageService.new(project, project.owner, params).execute
+
+ print '.'
+ end
+ end
+
+ def seed_maven_packages
+ 5.times do |i|
+ name = "my/company/app/maven-app-#{i}"
+ version = "1.0.#{i}-SNAPSHOT"
+
+ params = {
+ name: name,
+ version: version,
+ path: "#{name}/#{version}"
+ }
+
+ pkg = ::Packages::Maven::CreatePackageService.new(project, project.owner, params).execute
+
+ %w(maven-metadata.xml my-app-1.0-20180724.124855-1.pom my-app-1.0-20180724.124855-1.jar).each do |filename|
+ with_cloned_fixture_file('maven', filename) do |filepath|
+ file_params = {
+ file: UploadedFile.new(filepath, filename: filename),
+ file_name: filename,
+ file_sha1: '1234567890',
+ size: 100.kilobytes
+ }
+ ::Packages::CreatePackageFileService.new(pkg, file_params).execute
+ end
+ end
+
+ print '.'
+ end
+ end
+
+ def seed_conan_packages
+ 5.times do |i|
+ name = "my-conan-pkg-#{i}"
+ version = "2.0.#{i}"
+
+ params = {
+ package_name: name,
+ package_version: version,
+ package_username: ::Packages::Conan::Metadatum.package_username_from(full_path: project.full_path),
+ package_channel: 'stable'
+ }
+
+ pkg = ::Packages::Conan::CreatePackageService.new(project, project.owner, params).execute
+
+ fixtures = {
+ 'recipe_files' => %w(conanfile.py conanmanifest.txt),
+ 'package_files' => %w(conanmanifest.txt conaninfo.txt conan_package.tgz)
+ }
+
+ fixtures.each do |folder, filenames|
+ filenames.each do |filename|
+ with_cloned_fixture_file(File.join('conan', folder), filename) do |filepath|
+ file = UploadedFile.new(filepath, filename: filename)
+ file_params = {
+ file_name: filename,
+ 'file.sha1': '1234567890',
+ 'file.size': 100.kilobytes,
+ 'file.md5': '12345',
+ recipe_revision: '0',
+ package_revision: '0',
+ conan_package_reference: '123456789',
+ conan_file_type: :package_file
+ }
+ ::Packages::Conan::CreatePackageFileService.new(pkg, file, file_params).execute
+ end
+ end
+ end
+
+ print '.'
+ end
+ end
+
+ def seed_nuget_packages
+ 5.times do |i|
+ name = "MyNugetApp.Package#{i}"
+ version = "4.2.#{i}"
+
+ pkg = ::Packages::Nuget::CreatePackageService.new(project, project.owner, {}).execute
+ # when using ::Packages::Nuget::CreatePackageService, packages have a fixed name and a fixed version.
+ pkg.update!(name: name, version: version)
+
+ filename = 'package.nupkg'
+ with_cloned_fixture_file('nuget', filename) do |filepath|
+ file_params = {
+ file: UploadedFile.new(filepath, filename: filename),
+ file_name: filename,
+ file_sha1: '1234567890',
+ size: 100.kilobytes
+ }
+ ::Packages::CreatePackageFileService.new(pkg, file_params).execute
+ end
+
+ print '.'
+ end
+ end
+
+ private
+
+ def read_fixture_file(package_type, file)
+ File.read(fixture_path(package_type, file))
+ end
+
+ def fixture_path(package_type, file)
+ Rails.root.join('spec', 'fixtures', 'packages', package_type, file)
+ end
+
+ def with_cloned_fixture_file(package_type, file)
+ Dir.mktmpdir do |dirpath|
+ cloned_path = File.join(dirpath, file)
+ FileUtils.cp(fixture_path(package_type, file), cloned_path)
+ yield cloned_path
+ end
+ end
+end
+
+Gitlab::Seeder.quiet do
+ flag = 'SEED_ALL_PACKAGE_TYPES'
+
+ puts "Use the `#{flag}` environment variable to seed packages of all types." unless ENV[flag]
+
+ package_types = ENV[flag] ? %i[npm maven conan nuget] : [:npm]
+
+ Project.not_mass_generated.sample(5).each do |project|
+ puts "\nSeeding packages for the '#{project.full_path}' project"
+ seeder = Gitlab::Seeder::Packages.new(project)
+
+ package_types.each do |package_type|
+ seeder.seed_packages(package_type)
+ end
+ end
+end
diff --git a/db/fixtures/development/27_product_analytics_events.rb b/db/fixtures/development/27_product_analytics_events.rb
new file mode 100644
index 00000000000..19237afd8ea
--- /dev/null
+++ b/db/fixtures/development/27_product_analytics_events.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+Gitlab::Seeder.quiet do
+ # The data set takes approximately 2 minutes to load,
+ # so its put behind the flag. To seed this data use the flag and the filter:
+ # SEED_PRODUCT_ANALYTICS_EVENTS=1 FILTER=product_analytics_events rake db:seed_fu
+ flag = 'SEED_PRODUCT_ANALYTICS_EVENTS'
+
+ if ENV[flag]
+ Project.all.sample(2).each do |project|
+ # Let's generate approx a week of events from now into the past with 1 minute step.
+ # To add some differentiation we add a random offset of up to 45 seconds.
+ 10000.times do |i|
+ dvce_created_tstamp = DateTime.now - i.minute - rand(45).seconds
+
+ # Add a random delay to collector timestamp. Up to 2 seconds.
+ collector_tstamp = dvce_created_tstamp + rand(3).second
+
+ ProductAnalyticsEvent.create!(
+ project_id: project.id,
+ platform: ["web", "mob", "mob", "app"].sample,
+ collector_tstamp: collector_tstamp,
+ dvce_created_tstamp: dvce_created_tstamp,
+ event: nil,
+ event_id: SecureRandom.uuid,
+ name_tracker: "sp",
+ v_tracker: "js-2.14.0",
+ v_collector: Gitlab::VERSION,
+ v_etl: Gitlab::VERSION,
+ domain_userid: SecureRandom.uuid,
+ domain_sessionidx: 4,
+ page_url: "#{project.web_url}/-/product_analytics/test",
+ page_title: 'Test page',
+ page_referrer: "#{project.web_url}/-/product_analytics/test",
+ br_lang: ["en-US", "en-US", "en-GB", "nl", "fi"].sample, # https://www.andiamo.co.uk/resources/iso-language-codes/
+ br_features_pdf: true,
+ br_cookies: [true, true, true, false].sample,
+ br_colordepth: ["24", "24", "16", "8"].sample,
+ os_timezone: ["America/Los_Angeles", "America/Los_Angeles", "America/Lima", "Asia/Dubai", "Africa/Bangui"].sample, # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
+ doc_charset: ["UTF-8", "UTF-8", "UTF-8", "DOS", "EUC"].sample,
+ domain_sessionid: SecureRandom.uuid
+ )
+ end
+
+ unless Feature.enabled?(:product_analytics, project)
+ if Feature.enable(:product_analytics, project)
+ puts "Product analytics feature was enabled for #{project.full_path}"
+ end
+ end
+
+ puts "10K events added to #{project.full_path}"
+ end
+ else
+ puts "Skipped. Use the `#{flag}` environment variable to enable."
+ end
+end