Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20230214154101_fix_partition_ids_on_ci_sources_pipelines_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 44031175497259a913960da7a0a73a708b4ea627 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe FixPartitionIdsOnCiSourcesPipelines, migration: :gitlab_ci, feature_category: :continuous_integration do
  let(:sources_pipelines) { table(:ci_sources_pipelines, database: :ci) }

  before do
    sources_pipelines.insert_all!([
      { partition_id: 100, source_partition_id: 100 },
      { partition_id: 100, source_partition_id: 101 },
      { partition_id: 101, source_partition_id: 100 },
      { partition_id: 101, source_partition_id: 101 }
    ])
  end

  describe '#up' do
    context 'when on sass' do
      before do
        allow(Gitlab).to receive(:com?).and_return(true)
      end

      it 'fixes partition_id and source_partition_id' do
        expect { migrate! }.not_to raise_error

        expect(sources_pipelines.where(partition_id: 100).count).to eq(4)
        expect(sources_pipelines.where(partition_id: 101).count).to eq(0)
        expect(sources_pipelines.where(source_partition_id: 100).count).to eq(4)
        expect(sources_pipelines.where(source_partition_id: 101).count).to eq(0)
      end
    end

    context 'when on self managed' do
      it 'does not change partition_id or source_partition_id' do
        expect { migrate! }.not_to raise_error

        expect(sources_pipelines.where(partition_id: 100).count).to eq(2)
        expect(sources_pipelines.where(partition_id: 100).count).to eq(2)
        expect(sources_pipelines.where(source_partition_id: 101).count).to eq(2)
        expect(sources_pipelines.where(source_partition_id: 101).count).to eq(2)
      end
    end
  end
end