summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorJames Lopez <james@gitlab.com>2017-06-07 17:55:49 +0000
committerJames Lopez <james@gitlab.com>2017-06-07 17:55:49 +0000
commit1136c0c81a079e5de9321245c9b00a7ab61c30e6 (patch)
tree3bb49dfb5f31cda4480d70904d1b64e524c56ecf /spec/lib
parent6d09c1fed8f140670b6983faf536a7380e3271b0 (diff)
parent35a78da27f94e7b77c8487913beceb23db3b66bc (diff)
downloadgitlab-ce-1136c0c81a079e5de9321245c9b00a7ab61c30e6.tar.gz
Merge branch 'fix/backup-restore-resume' into 'master'
Fix backup task to continue on corrupt repositories Closes #31767 See merge request !11962
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/backup/repository_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/lib/gitlab/backup/repository_spec.rb b/spec/lib/gitlab/backup/repository_spec.rb
new file mode 100644
index 00000000000..51c1e9d657b
--- /dev/null
+++ b/spec/lib/gitlab/backup/repository_spec.rb
@@ -0,0 +1,63 @@
+require 'spec_helper'
+
+describe Backup::Repository, lib: true do
+ let(:progress) { StringIO.new }
+ let!(:project) { create(:empty_project) }
+
+ 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
+
+ allow_any_instance_of(described_class).to receive(:progress).and_return(progress)
+ end
+
+ describe '#dump' do
+ describe 'repo failure' do
+ before do
+ allow_any_instance_of(Repository).to receive(:empty_repo?).and_raise(Rugged::OdbError)
+ 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
+
+ expect(progress).to have_received(:puts).with("Ignoring repository error and continuing backing up project: #{project.full_path} - Rugged::OdbError")
+ end
+ end
+
+ describe 'command failure' do
+ before do
+ allow_any_instance_of(Repository).to receive(:empty_repo?).and_return(false)
+ 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
+ end
+ end
+
+ describe '#restore' do
+ 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
+
+ expect(progress).to have_received(:puts).with("Ignoring error on #{project.full_path} - error")
+ end
+ end
+ end
+end