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

gitlab_project_migration_common.rb « migration « 1_manage « api « features « specs « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 827ebc1f5e2709cd26c7ac0e77c11e024e578458 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true

module QA
  RSpec.shared_context 'with gitlab project migration' do
    let(:source_project_with_readme) { false }
    let(:import_wait_duration) { { max_duration: 300, sleep_interval: 2 } }
    let(:admin_api_client) { Runtime::API::Client.as_admin }
    let(:user) do
      Resource::User.fabricate_via_api! do |usr|
        usr.api_client = admin_api_client
        usr.hard_delete_on_api_removal = true
      end
    end

    let(:api_client) { Runtime::API::Client.new(user: user) }

    let(:sandbox) do
      Resource::Sandbox.fabricate_via_api! do |group|
        group.api_client = admin_api_client
      end
    end

    let(:destination_group) do
      Resource::Group.fabricate_via_api! do |group|
        group.api_client = api_client
        group.sandbox = sandbox
        group.path = "destination-group-for-import-#{SecureRandom.hex(4)}"
      end
    end

    let(:source_group) do
      Resource::Group.fabricate_via_api! do |group|
        group.api_client = api_client
        group.path = "source-group-for-import-#{SecureRandom.hex(4)}"
      end
    end

    let(:source_project) do
      Resource::Project.fabricate_via_api! do |project|
        project.api_client = api_client
        project.group = source_group
        project.initialize_with_readme = source_project_with_readme
      end
    end

    let(:imported_group) do
      Resource::BulkImportGroup.fabricate_via_api! do |group|
        group.api_client = api_client
        group.sandbox = destination_group
        group.source_group = source_group
      end
    end

    let(:imported_projects) { imported_group.reload!.projects }
    let(:imported_project) { imported_projects.first }

    let(:import_failures) do
      imported_group.import_details.sum([]) { |details| details[:failures] }
    end

    def expect_import_finished
      imported_group # trigger import

      expect { imported_group.import_status }.to eventually_eq('finished').within(import_wait_duration)
      expect(imported_projects.count).to eq(1), 'Expected to have 1 imported project'
    end

    before do
      Runtime::Feature.enable(:bulk_import_projects)

      sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
      source_project # fabricate source group and project
    end

    after do |example|
      # Checking for failures in the test currently makes test very flaky
      # Just log in case of failure until cause of network errors is found
      Runtime::Logger.warn("Import failures: #{import_failures}") if example.exception && !import_failures.empty?

      user.remove_via_api!
    ensure
      Runtime::Feature.disable(:bulk_import_projects)
    end
  end
end