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

import_sources_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b243780a020d25f6c0106d3308b44690917cd4f8 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::ImportSources, feature_category: :importers do
  describe '.options' do
    it 'returns a hash' do
      expected =
        {
          'GitHub' => 'github',
          'Bitbucket Cloud' => 'bitbucket',
          'Bitbucket Server' => 'bitbucket_server',
          'FogBugz' => 'fogbugz',
          'Repository by URL' => 'git',
          'GitLab export' => 'gitlab_project',
          'Gitea' => 'gitea',
          'Manifest file' => 'manifest'
        }

      expect(described_class.options).to eq(expected)
    end
  end

  describe '.values' do
    it 'returns an array' do
      expected =
        %w(
          github
          bitbucket
          bitbucket_server
          fogbugz
          git
          gitlab_project
          gitea
          manifest
        )

      expect(described_class.values).to eq(expected)
    end
  end

  describe '.importer_names' do
    it 'returns an array of importer names' do
      expected =
        %w(
          github
          bitbucket
          bitbucket_server
          fogbugz
          gitlab_project
          gitea
        )

      expect(described_class.importer_names).to eq(expected)
    end
  end

  describe '.importer' do
    import_sources = {
      'github' => Gitlab::GithubImport::ParallelImporter,
      'bitbucket' => Gitlab::BitbucketImport::Importer,
      'bitbucket_server' => Gitlab::BitbucketServerImport::ParallelImporter,
      'fogbugz' => Gitlab::FogbugzImport::Importer,
      'git' => nil,
      'gitlab_project' => Gitlab::ImportExport::Importer,
      'gitea' => Gitlab::LegacyGithubImport::Importer,
      'manifest' => nil
    }

    import_sources.each do |name, klass|
      it "returns #{klass} when given #{name}" do
        expect(described_class.importer(name)).to eq(klass)
      end
    end

    context 'when flag is disabled' do
      before do
        stub_feature_flags(bitbucket_server_parallel_importer: false)
      end

      it 'returns Gitlab::BitbucketServerImport::Importer when given bitbucket_server' do
        expect(described_class.importer('bitbucket_server')).to eq(Gitlab::BitbucketServerImport::Importer)
      end
    end
  end

  describe '.import_table' do
    subject { described_class.import_table }

    it 'returns the ParallelImporter for Bitbucket server' do
      is_expected.to include(
        described_class::ImportSource.new(
          'bitbucket_server',
          'Bitbucket Server',
          Gitlab::BitbucketServerImport::ParallelImporter
        )
      )
    end

    context 'when flag is disabled' do
      before do
        stub_feature_flags(bitbucket_server_parallel_importer: false)
      end

      it 'returns the legacy Importer for Bitbucket server' do
        is_expected.to include(
          described_class::ImportSource.new(
            'bitbucket_server',
            'Bitbucket Server',
            Gitlab::BitbucketServerImport::Importer
          )
        )
      end
    end
  end

  describe '.title' do
    import_sources = {
      'github' => 'GitHub',
      'bitbucket' => 'Bitbucket Cloud',
      'bitbucket_server' => 'Bitbucket Server',
      'fogbugz' => 'FogBugz',
      'git' => 'Repository by URL',
      'gitlab_project' => 'GitLab export',
      'gitea' => 'Gitea',
      'manifest' => 'Manifest file'
    }

    import_sources.each do |name, title|
      it "returns #{title} when given #{name}" do
        expect(described_class.title(name)).to eq(title)
      end
    end
  end

  describe 'imports_repository? checker' do
    let(:allowed_importers) { %w[github gitlab_project bitbucket_server] }

    it 'fails if any importer other than the allowed ones implements this method' do
      current_importers = described_class.values.select { |kind| described_class.importer(kind).try(:imports_repository?) }
      not_allowed_importers = current_importers - allowed_importers

      expect(not_allowed_importers).to be_empty, failure_message(not_allowed_importers)
    end

    def failure_message(importers_class_names)
      <<-MSG
        It looks like the #{importers_class_names.join(', ')} importers implements its own way to import the repository.
        That means that the lfs object download must be handled for each of them. You can use 'LfsImportService' and
        'LfsDownloadService' to implement it. After that, add the importer name to the list of allowed importers in this spec.
      MSG
    end
  end
end