summaryrefslogtreecommitdiff
path: root/spec/tasks/gitlab/backup_rake_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tasks/gitlab/backup_rake_spec.rb')
-rw-r--r--spec/tasks/gitlab/backup_rake_spec.rb75
1 files changed, 74 insertions, 1 deletions
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb
index 548e7780c36..287d83344db 100644
--- a/spec/tasks/gitlab/backup_rake_spec.rb
+++ b/spec/tasks/gitlab/backup_rake_spec.rb
@@ -9,6 +9,7 @@ describe 'gitlab:app namespace rake task' do
Rake.application.rake_require 'tasks/gitlab/backup'
Rake.application.rake_require 'tasks/gitlab/shell'
Rake.application.rake_require 'tasks/gitlab/db'
+ Rake.application.rake_require 'tasks/cache'
# empty task as env is already loaded
Rake::Task.define_task :environment
@@ -78,7 +79,7 @@ describe 'gitlab:app namespace rake task' do
end
end # backup_restore task
- describe 'backup_create' do
+ describe 'backup' do
def tars_glob
Dir.glob(File.join(Gitlab.config.backup.path, '*_gitlab_backup.tar'))
end
@@ -97,6 +98,78 @@ describe 'gitlab:app namespace rake task' do
@backup_tar = tars_glob.first
end
+ def restore_backup
+ orig_stdout = $stdout
+ $stdout = StringIO.new
+ reenable_backup_sub_tasks
+ run_rake_task('gitlab:backup:restore')
+ reenable_backup_sub_tasks
+ $stdout = orig_stdout
+ end
+
+ describe 'backup creation and deletion using annex and custom_hooks' do
+ let(:project) { create(:project) }
+ let(:user_backup_path) { "repositories/#{project.path_with_namespace}" }
+
+ before(:each) do
+ @origin_cd = Dir.pwd
+
+ path = File.join(project.repository.path_to_repo, filename)
+ FileUtils.mkdir_p(path)
+ FileUtils.touch(File.join(path, "dummy.txt"))
+
+ # We need to use the full path instead of the relative one
+ allow(Gitlab.config.gitlab_shell).to receive(:path).and_return(File.expand_path(Gitlab.config.gitlab_shell.path, Rails.root.to_s))
+
+ ENV["SKIP"] = "db"
+ create_backup
+ end
+
+ after(:each) do
+ ENV["SKIP"] = ""
+ FileUtils.rm(@backup_tar)
+ Dir.chdir(@origin_cd)
+ end
+
+ context 'project uses git-annex and successfully creates backup' do
+ let(:filename) { "annex" }
+
+ it 'creates annex.tar and project bundle' do
+ tar_contents, exit_status = Gitlab::Popen.popen(%W{tar -tvf #{@backup_tar}})
+
+ expect(exit_status).to eq(0)
+ expect(tar_contents).to match(user_backup_path)
+ expect(tar_contents).to match("#{user_backup_path}/annex.tar")
+ expect(tar_contents).to match("#{user_backup_path}.bundle")
+ end
+
+ it 'restores files correctly' do
+ restore_backup
+
+ expect(Dir.entries(File.join(project.repository.path, "annex"))).to include("dummy.txt")
+ end
+ end
+
+ context 'project uses custom_hooks and successfully creates backup' do
+ let(:filename) { "custom_hooks" }
+
+ it 'creates custom_hooks.tar and project bundle' do
+ tar_contents, exit_status = Gitlab::Popen.popen(%W{tar -tvf #{@backup_tar}})
+
+ expect(exit_status).to eq(0)
+ expect(tar_contents).to match(user_backup_path)
+ expect(tar_contents).to match("#{user_backup_path}/custom_hooks.tar")
+ expect(tar_contents).to match("#{user_backup_path}.bundle")
+ end
+
+ it 'restores files correctly' do
+ restore_backup
+
+ expect(Dir.entries(File.join(project.repository.path, "custom_hooks"))).to include("dummy.txt")
+ end
+ end
+ end
+
context 'tar creation' do
before do
create_backup