Commit bc5cc956 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Improve UpdateRepositoryStorageService spec

This used to use two faked storages, and to work around the that fact it
disabled the wikis and just tested if methods were called. Now this
tests the effects of the method calls and enables Gitaly again.
parent 564f05d1
require 'spec_helper'
describe Projects::UpdateRepositoryStorageService do
include StubConfiguration
include Gitlab::ShellAdapter
subject { described_class.new(project) }
......@@ -9,41 +9,23 @@ describe Projects::UpdateRepositoryStorageService do
let(:time) { Time.now }
before do
FileUtils.mkdir('tmp/tests/storage_a')
FileUtils.mkdir('tmp/tests/storage_b')
storages = {
'a' => { 'path' => 'tmp/tests/storage_a' },
'b' => { 'path' => 'tmp/tests/storage_b' }
}
stub_storage_settings(storages)
allow(Time).to receive(:now).and_return(time)
# This will force the creation of the repository and bypass Gitaly
allow_any_instance_of(Gitlab::Git::Repository).to receive(:exists?).and_return(false)
end
after do
FileUtils.rm_rf('tmp/tests/storage_a')
FileUtils.rm_rf('tmp/tests/storage_b')
end
context 'without wiki', :disable_gitaly do
let(:project) { create(:project, :repository, repository_storage: 'a', repository_read_only: true, wiki_enabled: false) }
context 'without wiki' do
let(:project) { create(:project, :repository, repository_read_only: true, wiki_enabled: false) }
context 'when the move succeeds' do
it 'moves the repository to the new storage and unmarks the repository as read only' do
old_path = project.repository.path_to_repo
expect_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror)
.with(project.repository.raw).and_return(true)
expect(GitlabShellWorker).to receive(:perform_async)
.with(:mv_repository, 'a', project.disk_path,
"#{project.disk_path}+#{project.id}+moved+#{time.to_i}")
subject.execute('b')
subject.execute('test_second_storage')
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('b')
expect(project.repository_storage).to eq('test_second_storage')
expect(gitlab_shell.exists?('default', old_path)).to be(false)
end
end
......@@ -53,56 +35,53 @@ describe Projects::UpdateRepositoryStorageService do
.with(project.repository.raw).and_return(false)
expect(GitlabShellWorker).not_to receive(:perform_async)
subject.execute('b')
subject.execute('test_second_storage')
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('a')
expect(project.repository_storage).to eq('default')
end
end
end
context 'with wiki', :disable_gitaly do
let(:project) { create(:project, :repository, repository_storage: 'a', repository_read_only: true, wiki_enabled: true) }
let(:project) { create(:project, :repository, repository_read_only: true, wiki_enabled: true) }
let(:repository_double) { double(:repository) }
let(:wiki_repository_double) { double(:repository) }
before do
allow_any_instance_of(Gitlab::Git::Repository).to receive(:exists?).and_return(false)
project.create_wiki
allow_any_instance_of(Gitlab::Git::Repository).to receive(:exists?).and_return(true)
# Default stub for non-specified params
allow(Gitlab::Git::Repository).to receive(:new).and_call_original
relative_path = project.repository.raw.relative_path
allow(Gitlab::Git::Repository).to receive(:new)
.with('b', relative_path, "project-#{project.id}")
.with('test_second_storage', relative_path, "project-#{project.id}")
.and_return(repository_double)
wiki_relative_path = project.wiki.repository.raw.relative_path
allow(Gitlab::Git::Repository).to receive(:new)
.with('b', wiki_relative_path, "wiki-#{project.id}")
.with('test_second_storage', wiki_relative_path, "wiki-#{project.id}")
.and_return(wiki_repository_double)
end
context 'when the move succeeds' do
it 'moves the repository and its wiki to the new storage and unmarks the repository as read only' do
old_path = project.repository.path_to_repo
old_wiki_path = project.wiki.full_path
expect(repository_double).to receive(:fetch_repository_as_mirror)
.with(project.repository.raw).and_return(true)
expect(GitlabShellWorker).to receive(:perform_async)
.with(:mv_repository, "a", project.disk_path,
"#{project.disk_path}+#{project.id}+moved+#{time.to_i}")
expect(wiki_repository_double).to receive(:fetch_repository_as_mirror)
.with(project.wiki.repository.raw).and_return(true)
expect(GitlabShellWorker).to receive(:perform_async)
.with(:mv_repository, "a", project.wiki.disk_path,
"#{project.disk_path}+#{project.id}+moved+#{time.to_i}.wiki")
subject.execute('b')
subject.execute('test_second_storage')
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('b')
expect(project.repository_storage).to eq('test_second_storage')
expect(gitlab_shell.exists?('default', old_path)).to be(false)
expect(gitlab_shell.exists?('default', old_wiki_path)).to be(false)
end
end
......@@ -114,10 +93,10 @@ describe Projects::UpdateRepositoryStorageService do
.with(project.wiki.repository.raw).and_return(false)
expect(GitlabShellWorker).not_to receive(:perform_async)
subject.execute('b')
subject.execute('test_second_storage')
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('a')
expect(project.repository_storage).to eq('default')
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment