debian-mirror-gitlab/spec/lib/gitlab/import_sources_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

155 lines
4.4 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-07-09 08:55:56 +05:30
RSpec.describe Gitlab::ImportSources, feature_category: :importers do
2017-08-17 22:00:37 +05:30
describe '.options' do
it 'returns a hash' do
expected =
{
2022-10-11 01:57:18 +05:30
'GitHub' => 'github',
'Bitbucket Cloud' => 'bitbucket',
'Bitbucket Server' => 'bitbucket_server',
'FogBugz' => 'fogbugz',
2022-07-23 23:45:48 +05:30
'Repository by URL' => 'git',
2022-10-11 01:57:18 +05:30
'GitLab export' => 'gitlab_project',
'Gitea' => 'gitea',
2023-07-09 08:55:56 +05:30
'Manifest file' => 'manifest'
2017-08-17 22:00:37 +05:30
}
expect(described_class.options).to eq(expected)
end
end
describe '.values' do
it 'returns an array' do
expected =
%w(
github
bitbucket
2018-11-18 11:00:15 +05:30
bitbucket_server
2017-08-17 22:00:37 +05:30
fogbugz
git
gitlab_project
gitea
2018-11-18 11:00:15 +05:30
manifest
2017-08-17 22:00:37 +05:30
)
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
2018-11-18 11:00:15 +05:30
bitbucket_server
2017-08-17 22:00:37 +05:30
fogbugz
gitlab_project
gitea
)
expect(described_class.importer_names).to eq(expected)
end
end
describe '.importer' do
import_sources = {
2018-03-17 18:26:18 +05:30
'github' => Gitlab::GithubImport::ParallelImporter,
2017-08-17 22:00:37 +05:30
'bitbucket' => Gitlab::BitbucketImport::Importer,
2023-06-20 00:43:36 +05:30
'bitbucket_server' => Gitlab::BitbucketServerImport::ParallelImporter,
2017-08-17 22:00:37 +05:30
'fogbugz' => Gitlab::FogbugzImport::Importer,
'git' => nil,
'gitlab_project' => Gitlab::ImportExport::Importer,
2018-11-18 11:00:15 +05:30
'gitea' => Gitlab::LegacyGithubImport::Importer,
2023-07-09 08:55:56 +05:30
'manifest' => nil
2017-08-17 22:00:37 +05:30
}
import_sources.each do |name, klass|
it "returns #{klass} when given #{name}" do
expect(described_class.importer(name)).to eq(klass)
end
end
2023-06-20 00:43:36 +05:30
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
2017-08-17 22:00:37 +05:30
end
describe '.title' do
import_sources = {
'github' => 'GitHub',
2018-11-18 11:00:15 +05:30
'bitbucket' => 'Bitbucket Cloud',
'bitbucket_server' => 'Bitbucket Server',
2017-08-17 22:00:37 +05:30
'fogbugz' => 'FogBugz',
2022-07-23 23:45:48 +05:30
'git' => 'Repository by URL',
2017-08-17 22:00:37 +05:30
'gitlab_project' => 'GitLab export',
2018-11-18 11:00:15 +05:30
'gitea' => 'Gitea',
2023-07-09 08:55:56 +05:30
'manifest' => 'Manifest file'
2017-08-17 22:00:37 +05:30
}
import_sources.each do |name, title|
it "returns #{title} when given #{name}" do
expect(described_class.title(name)).to eq(title)
end
end
end
2018-11-08 19:23:39 +05:30
describe 'imports_repository? checker' do
2023-07-09 08:55:56 +05:30
let(:allowed_importers) { %w[github gitlab_project bitbucket_server] }
2018-11-08 19:23:39 +05:30
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
2017-08-17 22:00:37 +05:30
end