2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::ImportExport::RepoRestorer do
|
2018-12-05 23:21:45 +05:30
|
|
|
include GitHelpers
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:project_with_repo) do
|
|
|
|
create(:project, :repository, :wiki_repo, name: 'test-repo-restorer', path: 'test-repo-restorer').tap do |p|
|
|
|
|
p.wiki.create_page('page', 'foobar', :markdown, 'created page')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:project) { create(:project) }
|
|
|
|
|
|
|
|
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
|
|
|
|
let(:shared) { project.import_export_shared }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
|
|
|
|
|
|
|
|
bundler.save
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
FileUtils.rm_rf(export_path)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe 'bundle a project Git repo' do
|
|
|
|
let(:bundler) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) }
|
|
|
|
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) }
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
after do
|
2021-02-22 17:27:13 +05:30
|
|
|
Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'restores the repo successfully' do
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(project.repository.exists?).to be false
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject.restore).to be_truthy
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
expect(project.repository.empty?).to be false
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'when the repository already exists' do
|
|
|
|
it 'deletes the existing repository before importing' do
|
|
|
|
allow(project.repository).to receive(:exists?).and_return(true)
|
|
|
|
allow(project.repository).to receive(:path).and_return('repository_path')
|
|
|
|
|
|
|
|
expect_next_instance_of(Repositories::DestroyService) do |instance|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(instance).to receive(:execute).and_call_original
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(shared.logger).to receive(:info).with(
|
|
|
|
message: 'Deleting existing "repository_path" to re-import it.'
|
|
|
|
)
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(subject.restore).to be_truthy
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
describe 'restore a wiki Git repo' do
|
|
|
|
let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_with_repo, shared: shared) }
|
|
|
|
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.wiki_repo_bundle_filename) }
|
|
|
|
|
|
|
|
subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: ProjectWiki.new(project)) }
|
|
|
|
|
|
|
|
after do
|
|
|
|
Gitlab::Shell.new.remove_repository(project.wiki.repository_storage, project.wiki.disk_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'restores the wiki repo successfully' do
|
|
|
|
expect(project.wiki_repository_exists?).to be false
|
|
|
|
|
|
|
|
subject.restore
|
|
|
|
project.wiki.repository.expire_status_cache
|
|
|
|
|
|
|
|
expect(project.wiki_repository_exists?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'no wiki in the bundle' do
|
|
|
|
let!(:project_without_wiki) { create(:project) }
|
|
|
|
|
|
|
|
let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_without_wiki, shared: shared) }
|
|
|
|
|
|
|
|
it 'does not creates an empty wiki' do
|
|
|
|
expect(subject.restore).to be true
|
|
|
|
expect(project.wiki_repository_exists?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|