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

backfill_ci_namespace_mirrors_spec.rb « background_migration « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8980a26932bac702d15f5747b5aae23823de52f2 (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'

RSpec.describe Gitlab::BackgroundMigration::BackfillCiNamespaceMirrors, :migration, schema: 20211208122200 do
  let(:namespaces) { table(:namespaces) }
  let(:ci_namespace_mirrors) { table(:ci_namespace_mirrors) }

  subject { described_class.new }

  describe '#perform' do
    it 'creates hierarchies for all namespaces in range' do
      namespaces.create!(id: 5, name: 'test1', path: 'test1')
      namespaces.create!(id: 7, name: 'test2', path: 'test2')
      namespaces.create!(id: 8, name: 'test3', path: 'test3')

      subject.perform(5, 7)

      expect(ci_namespace_mirrors.all).to contain_exactly(
        an_object_having_attributes(namespace_id: 5, traversal_ids: [5]),
        an_object_having_attributes(namespace_id: 7, traversal_ids: [7])
      )
    end

    it 'handles existing hierarchies gracefully' do
      namespaces.create!(id: 5, name: 'test1', path: 'test1')
      test2 = namespaces.create!(id: 7, name: 'test2', path: 'test2')
      namespaces.create!(id: 8, name: 'test3', path: 'test3', parent_id: 7)
      namespaces.create!(id: 9, name: 'test4', path: 'test4')

      # Simulate a situation where a user has had a chance to move a group to another parent
      # before the background migration has had a chance to run
      test2.update!(parent_id: 5)
      ci_namespace_mirrors.create!(namespace_id: test2.id, traversal_ids: [5, 7])

      subject.perform(5, 8)

      expect(ci_namespace_mirrors.all).to contain_exactly(
        an_object_having_attributes(namespace_id: 5, traversal_ids: [5]),
        an_object_having_attributes(namespace_id: 7, traversal_ids: [5, 7]),
        an_object_having_attributes(namespace_id: 8, traversal_ids: [5, 7, 8])
      )
    end
  end
end