summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values_spec.rb')
-rw-r--r--spec/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values_spec.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values_spec.rb b/spec/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values_spec.rb
new file mode 100644
index 00000000000..423b1815e75
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values_spec.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::ResetDuplicateCiRunnersTokenValues,
+ :migration,
+ schema: 20220922143143 do
+ it { expect(described_class).to be < Gitlab::BackgroundMigration::BatchedMigrationJob }
+
+ describe '#perform' do
+ let(:ci_runners) { table(:ci_runners, database: :ci) }
+
+ let(:test_worker) do
+ described_class.new(
+ start_id: 1,
+ end_id: 4,
+ batch_table: :ci_runners,
+ batch_column: :id,
+ sub_batch_size: 2,
+ pause_ms: 0,
+ connection: Ci::ApplicationRecord.connection
+ )
+ end
+
+ subject(:perform) { test_worker.perform }
+
+ before do
+ ci_runners.create!(id: 1, runner_type: 1, token: 'duplicate')
+ ci_runners.create!(id: 2, runner_type: 1, token: 'a-token')
+ ci_runners.create!(id: 3, runner_type: 1, token: 'duplicate-2')
+ ci_runners.create!(id: 4, runner_type: 1, token: nil)
+ ci_runners.create!(id: 5, runner_type: 1, token: 'duplicate-2')
+ ci_runners.create!(id: 6, runner_type: 1, token: 'duplicate')
+ ci_runners.create!(id: 7, runner_type: 1, token: 'another-token')
+ ci_runners.create!(id: 8, runner_type: 1, token: 'another-token')
+ end
+
+ it 'nullifies duplicate tokens', :aggregate_failures do
+ expect { perform }.to change { ci_runners.all.order(:id).pluck(:id, :token).to_h }
+ .from(
+ {
+ 1 => 'duplicate',
+ 2 => 'a-token',
+ 3 => 'duplicate-2',
+ 4 => nil,
+ 5 => 'duplicate-2',
+ 6 => 'duplicate',
+ 7 => 'another-token',
+ 8 => 'another-token'
+ }
+ )
+ .to(
+ {
+ 1 => nil,
+ 2 => 'a-token',
+ 3 => nil,
+ 4 => nil,
+ 5 => nil,
+ 6 => nil,
+ 7 => 'another-token',
+ 8 => 'another-token'
+ }
+ )
+ expect(ci_runners.count).to eq(8)
+ expect(ci_runners.pluck(:token).uniq).to match_array [
+ nil, 'a-token', 'another-token'
+ ]
+ end
+ end
+end