diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-28 12:09:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-28 12:09:23 +0300 |
commit | dba63244c19187d32f1f998403555f1893f5abdb (patch) | |
tree | d07f5aa931f280617456f80c5c139789598290cf /spec/migrations/20230313142631_backfill_ml_candidates_package_id_spec.rb | |
parent | 66d107f9394f719c63cb30f53d62b5b5db888e4b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations/20230313142631_backfill_ml_candidates_package_id_spec.rb')
-rw-r--r-- | spec/migrations/20230313142631_backfill_ml_candidates_package_id_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/migrations/20230313142631_backfill_ml_candidates_package_id_spec.rb b/spec/migrations/20230313142631_backfill_ml_candidates_package_id_spec.rb new file mode 100644 index 00000000000..57ddb0504ec --- /dev/null +++ b/spec/migrations/20230313142631_backfill_ml_candidates_package_id_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe BackfillMlCandidatesPackageId, feature_category: :mlops do + let(:migration) { described_class.new } + + let(:projects) { table(:projects) } + let(:namespaces) { table(:namespaces) } + let(:ml_experiments) { table(:ml_experiments) } + let(:ml_candidates) { table(:ml_candidates) } + let(:packages_packages) { table(:packages_packages) } + + let(:namespace) { namespaces.create!(name: 'foo', path: 'foo') } + let(:project) { projects.create!(project_namespace_id: namespace.id, namespace_id: namespace.id) } + let(:experiment) { ml_experiments.create!(project_id: project.id, iid: 1, name: 'experiment') } + let!(:candidate1) { ml_candidates.create!(experiment_id: experiment.id, iid: SecureRandom.uuid) } + let!(:candidate2) { ml_candidates.create!(experiment_id: experiment.id, iid: SecureRandom.uuid) } + let!(:package1) do + packages_packages.create!( + project_id: project.id, + name: "ml_candidate_#{candidate1.id}", + version: "-", + package_type: 7 + ) + end + + let!(:package2) do + packages_packages.create!( + project_id: project.id, + name: "ml_candidate_1000", + version: "-", + package_type: 7) + end + + let!(:package3) do + packages_packages.create!( + project_id: project.id, + name: "ml_candidate_abcde", + version: "-", + package_type: 7 + ) + end + + describe '#up' do + it 'sets the correct package_ids with idempotency', :aggregate_failures do + migration.up + + expect(candidate1.reload.package_id).to be(package1.id) + expect(candidate2.reload.package_id).to be(nil) + + migration.down + migration.up + + expect(candidate1.reload.package_id).to be(package1.id) + expect(candidate2.reload.package_id).to be(nil) + end + end +end |