diff options
Diffstat (limited to 'spec/lib/backup')
-rw-r--r-- | spec/lib/backup/manager_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/backup/object_backup_spec.rb | 36 | ||||
-rw-r--r-- | spec/lib/backup/terraform_state_spec.rb | 27 |
3 files changed, 39 insertions, 30 deletions
diff --git a/spec/lib/backup/manager_spec.rb b/spec/lib/backup/manager_spec.rb index 0e26e2faa5c..31cc3012eb1 100644 --- a/spec/lib/backup/manager_spec.rb +++ b/spec/lib/backup/manager_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Backup::Manager do end describe '#pack' do - let(:expected_backup_contents) { %w(repositories db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz terraform_state.tar.gz backup_information.yml) } + let(:expected_backup_contents) { %w(repositories db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz terraform_state.tar.gz packages.tar.gz backup_information.yml) } let(:tar_file) { '1546300800_2019_01_01_12.3_gitlab_backup.tar' } let(:tar_system_options) { { out: [tar_file, 'w', Gitlab.config.backup.archive_permissions] } } let(:tar_cmdline) { ['tar', '-cf', '-', *expected_backup_contents, tar_system_options] } @@ -57,7 +57,7 @@ RSpec.describe Backup::Manager do end context 'when skipped is set in backup_information.yml' do - let(:expected_backup_contents) { %w{db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz terraform_state.tar.gz backup_information.yml} } + let(:expected_backup_contents) { %w{db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz terraform_state.tar.gz packages.tar.gz backup_information.yml} } let(:backup_information) do { backup_created_at: Time.zone.parse('2019-01-01'), @@ -74,7 +74,7 @@ RSpec.describe Backup::Manager do end context 'when a directory does not exist' do - let(:expected_backup_contents) { %w{db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz terraform_state.tar.gz backup_information.yml} } + let(:expected_backup_contents) { %w{db uploads.tar.gz builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz terraform_state.tar.gz packages.tar.gz backup_information.yml} } before do expect(Dir).to receive(:exist?).with(File.join(Gitlab.config.backup.path, 'repositories')).and_return(false) diff --git a/spec/lib/backup/object_backup_spec.rb b/spec/lib/backup/object_backup_spec.rb new file mode 100644 index 00000000000..6192b5c3482 --- /dev/null +++ b/spec/lib/backup/object_backup_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.shared_examples 'backup object' do |setting| + let(:progress) { StringIO.new } + let(:backup_path) { "/var/#{setting}" } + + subject(:backup) { described_class.new(progress) } + + describe '#dump' do + before do + allow(File).to receive(:realpath).and_call_original + allow(File).to receive(:realpath).with(backup_path).and_return(backup_path) + allow(File).to receive(:realpath).with("#{backup_path}/..").and_return('/var') + allow(Settings.send(setting)).to receive(:storage_path).and_return(backup_path) + end + + it 'uses the correct storage dir in tar command and excludes tmp', :aggregate_failures do + expect(backup.app_files_dir).to eq(backup_path) + expect(backup).to receive(:tar).and_return('blabla-tar') + expect(backup).to receive(:run_pipeline!).with([%W(blabla-tar --exclude=lost+found --exclude=./tmp -C #{backup_path} -cf - .), 'gzip -c -1'], any_args).and_return([[true, true], '']) + expect(backup).to receive(:pipeline_succeeded?).and_return(true) + + backup.dump + end + end +end + +RSpec.describe Backup::Packages do + it_behaves_like 'backup object', 'packages' +end + +RSpec.describe Backup::TerraformState do + it_behaves_like 'backup object', 'terraform_state' +end diff --git a/spec/lib/backup/terraform_state_spec.rb b/spec/lib/backup/terraform_state_spec.rb deleted file mode 100644 index 56051501204..00000000000 --- a/spec/lib/backup/terraform_state_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Backup::TerraformState do - let(:progress) { StringIO.new } - - subject(:backup) { described_class.new(progress) } - - describe '#dump' do - before do - allow(File).to receive(:realpath).and_call_original - allow(File).to receive(:realpath).with('/var/terraform_state').and_return('/var/terraform_state') - allow(File).to receive(:realpath).with('/var/terraform_state/..').and_return('/var') - allow(Settings.terraform_state).to receive(:storage_path).and_return('/var/terraform_state') - end - - it 'uses the correct storage dir in tar command and excludes tmp', :aggregate_failures do - expect(backup.app_files_dir).to eq('/var/terraform_state') - expect(backup).to receive(:tar).and_return('blabla-tar') - expect(backup).to receive(:run_pipeline!).with([%w(blabla-tar --exclude=lost+found --exclude=./tmp -C /var/terraform_state -cf - .), 'gzip -c -1'], any_args).and_return([[true, true], '']) - expect(backup).to receive(:pipeline_succeeded?).and_return(true) - - backup.dump - end - end -end |