2017-06-07 04:38:12 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Backup::Repository do
|
2017-06-07 04:38:12 -04:00
|
|
|
let(:progress) { StringIO.new }
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project) { create(:project) }
|
2017-06-07 04:38:12 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(progress).to receive(:puts)
|
|
|
|
allow(progress).to receive(:print)
|
|
|
|
|
|
|
|
allow_any_instance_of(String).to receive(:color) do |string, _color|
|
|
|
|
string
|
|
|
|
end
|
|
|
|
|
2017-06-07 10:50:21 -04:00
|
|
|
allow_any_instance_of(described_class).to receive(:progress).and_return(progress)
|
2017-06-07 04:38:12 -04:00
|
|
|
end
|
|
|
|
|
2017-06-07 09:49:35 -04:00
|
|
|
describe '#dump' do
|
2017-06-07 08:57:26 -04:00
|
|
|
describe 'repo failure' do
|
|
|
|
before do
|
2017-06-07 10:50:21 -04:00
|
|
|
allow_any_instance_of(Repository).to receive(:empty_repo?).and_raise(Rugged::OdbError)
|
2017-06-07 08:57:26 -04:00
|
|
|
allow(Gitlab::Popen).to receive(:popen).and_return(['normal output', 0])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error' do
|
|
|
|
expect { described_class.new.dump }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the appropriate error' do
|
|
|
|
described_class.new.dump
|
|
|
|
|
2017-06-07 10:50:21 -04:00
|
|
|
expect(progress).to have_received(:puts).with("Ignoring repository error and continuing backing up project: #{project.full_path} - Rugged::OdbError")
|
2017-06-07 08:57:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'command failure' do
|
|
|
|
before do
|
2017-06-07 10:50:21 -04:00
|
|
|
allow_any_instance_of(Repository).to receive(:empty_repo?).and_return(false)
|
2017-06-07 08:57:26 -04:00
|
|
|
allow(Gitlab::Popen).to receive(:popen).and_return(['error', 1])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the appropriate error' do
|
|
|
|
described_class.new.dump
|
|
|
|
|
|
|
|
expect(progress).to have_received(:puts).with("Ignoring error on #{project.full_path} - error")
|
|
|
|
end
|
2017-06-07 04:38:12 -04:00
|
|
|
end
|
2017-06-07 08:57:26 -04:00
|
|
|
end
|
|
|
|
|
2017-06-07 09:49:35 -04:00
|
|
|
describe '#restore' do
|
2017-06-07 08:57:26 -04:00
|
|
|
describe 'command failure' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Popen).to receive(:popen).and_return(['error', 1])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the appropriate error' do
|
|
|
|
described_class.new.restore
|
2017-06-07 04:38:12 -04:00
|
|
|
|
2017-06-07 08:57:26 -04:00
|
|
|
expect(progress).to have_received(:puts).with("Ignoring error on #{project.full_path} - error")
|
|
|
|
end
|
2017-06-07 04:38:12 -04:00
|
|
|
end
|
|
|
|
end
|
2017-07-25 19:51:37 -04:00
|
|
|
|
|
|
|
describe '#empty_repo?' do
|
|
|
|
context 'for a wiki' do
|
|
|
|
let(:wiki) { create(:project_wiki) }
|
|
|
|
|
|
|
|
context 'wiki repo has content' do
|
|
|
|
let!(:wiki_page) { create(:wiki_page, wiki: wiki) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
wiki.repository.exists? # initial cache
|
|
|
|
end
|
|
|
|
|
|
|
|
context '`repository.exists?` is incorrectly cached as false' do
|
|
|
|
before do
|
|
|
|
repo = wiki.repository
|
|
|
|
repo.send(:cache).expire(:exists?)
|
|
|
|
repo.send(:cache).fetch(:exists?) { false }
|
|
|
|
repo.send(:instance_variable_set, :@exists, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false, regardless of bad cache value' do
|
2017-07-28 12:53:12 -04:00
|
|
|
expect(described_class.new.send(:empty_repo?, wiki)).to be_falsey
|
2017-07-25 19:51:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '`repository.exists?` is correctly cached as true' do
|
|
|
|
it 'returns false' do
|
2017-07-28 12:53:12 -04:00
|
|
|
expect(described_class.new.send(:empty_repo?, wiki)).to be_falsey
|
2017-07-25 19:51:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'wiki repo does not have content' do
|
|
|
|
context '`repository.exists?` is incorrectly cached as true' do
|
|
|
|
before do
|
|
|
|
repo = wiki.repository
|
|
|
|
repo.send(:cache).expire(:exists?)
|
|
|
|
repo.send(:cache).fetch(:exists?) { true }
|
|
|
|
repo.send(:instance_variable_set, :@exists, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true, regardless of bad cache value' do
|
2017-07-28 12:53:12 -04:00
|
|
|
expect(described_class.new.send(:empty_repo?, wiki)).to be_truthy
|
2017-07-25 19:51:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '`repository.exists?` is correctly cached as false' do
|
|
|
|
it 'returns true' do
|
2017-07-28 12:53:12 -04:00
|
|
|
expect(described_class.new.send(:empty_repo?, wiki)).to be_truthy
|
2017-07-25 19:51:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-06-07 04:38:12 -04:00
|
|
|
end
|