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

backfill_ci_project_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: 4eec83879e36c8df763927a3a2d1cc72f4cc6a8a (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
46
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BackgroundMigration::BackfillCiProjectMirrors, :migration, schema: 20211208122201 do
  let(:namespaces) { table(:namespaces) }
  let(:projects) { table(:projects) }
  let(:ci_project_mirrors) { table(:ci_project_mirrors) }

  subject { described_class.new }

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

      subject.perform(5, 7)

      expect(ci_project_mirrors.all).to contain_exactly(
        an_object_having_attributes(project_id: 5, namespace_id: 10),
        an_object_having_attributes(project_id: 7, namespace_id: 10)
      )
    end

    it 'handles existing ci_project_mirrors gracefully' do
      namespaces.create!(id: 10, name: 'namespace1', path: 'namespace1')
      namespaces.create!(id: 11, name: 'namespace2', path: 'namespace2', parent_id: 10)
      projects.create!(id: 5, namespace_id: 10, name: 'test1', path: 'test1')
      projects.create!(id: 7, namespace_id: 11, name: 'test2', path: 'test2')
      projects.create!(id: 8, namespace_id: 11, name: 'test3', path: 'test3')

      # Simulate a situation where a user has had a chance to move a project to another namespace
      # before the background migration has had a chance to run
      ci_project_mirrors.create!(project_id: 7, namespace_id: 10)

      subject.perform(5, 7)

      expect(ci_project_mirrors.all).to contain_exactly(
        an_object_having_attributes(project_id: 5, namespace_id: 10),
        an_object_having_attributes(project_id: 7, namespace_id: 10)
      )
    end
  end
end