summaryrefslogtreecommitdiff
path: root/spec/lib/backup
diff options
context:
space:
mode:
authorBalasankar "Balu" C <balasankar@gitlab.com>2018-03-30 11:38:30 +0530
committerBalasankar "Balu" C <balasankar@gitlab.com>2018-03-30 11:38:36 +0530
commitc0ef9958ff5bfbd78df44b2d5abe4d5375a0d36f (patch)
treebb6d944fa80e1f6dbea145915e98ae8280240c62 /spec/lib/backup
parent8785f237959a1e59fee8f628b76e476040848e24 (diff)
downloadgitlab-ce-c0ef9958ff5bfbd78df44b2d5abe4d5375a0d36f.tar.gz
Add basic tests
Diffstat (limited to 'spec/lib/backup')
-rw-r--r--spec/lib/backup/files_spec.rb44
-rw-r--r--spec/lib/backup/repository_spec.rb11
2 files changed, 55 insertions, 0 deletions
diff --git a/spec/lib/backup/files_spec.rb b/spec/lib/backup/files_spec.rb
new file mode 100644
index 00000000000..efc9ff0d7d3
--- /dev/null
+++ b/spec/lib/backup/files_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe Backup::Files do
+ let(:progress) { StringIO.new }
+ let!(:project) { create(:project) }
+
+ before do
+ allow(progress).to receive(:puts)
+ allow(progress).to receive(:print)
+ allow(FileUtils).to receive(:mkdir_p).and_return(true)
+ allow(FileUtils).to receive(:mv).and_return(true)
+
+ 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 '#restore' do
+ subject { described_class.new('registry', '/var/gitlab-registry') }
+ let(:timestamp) { Time.utc(2017, 3, 22) }
+
+ around do |example|
+ Timecop.freeze(timestamp) { example.run }
+ end
+
+ describe 'folders without permissions' do
+ before do
+
+ allow(File).to receive(:realpath).with("/var/gitlab-registry").and_return("/var/gitlab-registry")
+ allow(File).to receive(:realpath).with("/var/gitlab-registry/..").and_return("/var")
+ allow(File).to receive(:exist?).and_return(true)
+ allow(FileUtils).to receive(:mv).and_raise(Errno::EACCES)
+ allow(subject).to receive(:run_pipeline!).and_return(true)
+ end
+
+ it 'shows error message' do
+ expect(subject).to receive(:access_denied_error).with("/var/gitlab-registry")
+ subject.restore
+ end
+ end
+ end
+end
diff --git a/spec/lib/backup/repository_spec.rb b/spec/lib/backup/repository_spec.rb
index 7d774c5f63e..e4c1c9bafc0 100644
--- a/spec/lib/backup/repository_spec.rb
+++ b/spec/lib/backup/repository_spec.rb
@@ -70,6 +70,17 @@ describe Backup::Repository do
end
end
end
+
+ describe 'folders without permissions' do
+ before do
+ allow(FileUtils).to receive(:mv).and_raise(Errno::EACCES)
+ end
+
+ it 'shows error message' do
+ expect(subject).to receive(:access_denied_error)
+ subject.restore
+ end
+ end
end
describe '#empty_repo?' do