diff options
Diffstat (limited to 'spec/lib/backup/database_spec.rb')
-rw-r--r-- | spec/lib/backup/database_spec.rb | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/spec/lib/backup/database_spec.rb b/spec/lib/backup/database_spec.rb index 4345778ba92..53db7f0f149 100644 --- a/spec/lib/backup/database_spec.rb +++ b/spec/lib/backup/database_spec.rb @@ -6,25 +6,49 @@ RSpec.describe Backup::Database do let(:progress) { StringIO.new } let(:output) { progress.string } - before do - allow(Gitlab::TaskHelpers).to receive(:ask_to_continue) + before(:all) do + Rake.application.rake_require 'active_record/railties/databases' + 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' end describe '#restore' do let(:cmd) { %W[#{Gem.ruby} -e $stdout.puts(1)] } let(:data) { Rails.root.join("spec/fixtures/pages_empty.tar.gz").to_s } + let(:force) { true } - subject { described_class.new(progress, filename: data) } + subject { described_class.new(progress, force: force) } before do allow(subject).to receive(:pg_restore_cmd).and_return(cmd) end + context 'when not forced' do + let(:force) { false } + + it 'warns the user and waits' do + expect(subject).to receive(:sleep) + expect(Rake::Task['gitlab:db:drop_tables']).to receive(:invoke) + + subject.restore(data) + + expect(output).to include('Removing all tables. Press `Ctrl-C` within 5 seconds to abort') + end + + it 'has a pre restore warning' do + expect(subject.pre_restore_warning).not_to be_nil + end + end + context 'with an empty .gz file' do let(:data) { Rails.root.join("spec/fixtures/pages_empty.tar.gz").to_s } it 'returns successfully' do - subject.restore + expect(Rake::Task['gitlab:db:drop_tables']).to receive(:invoke) + + subject.restore(data) expect(output).to include("Restoring PostgreSQL database") expect(output).to include("[DONE]") @@ -36,7 +60,9 @@ RSpec.describe Backup::Database do let(:data) { Rails.root.join("spec/fixtures/big-image.png").to_s } it 'raises a backup error' do - expect { subject.restore }.to raise_error(Backup::Error) + expect(Rake::Task['gitlab:db:drop_tables']).to receive(:invoke) + + expect { subject.restore(data) }.to raise_error(Backup::Error) end end @@ -45,12 +71,15 @@ RSpec.describe Backup::Database do let(:noise) { "Table projects does not exist\nmust be owner of extension pg_trgm\nWARNING: no privileges could be revoked for public\n" } let(:cmd) { %W[#{Gem.ruby} -e $stderr.write("#{noise}#{visible_error}")] } - it 'filters out noise from errors' do - subject.restore + it 'filters out noise from errors and has a post restore warning' do + expect(Rake::Task['gitlab:db:drop_tables']).to receive(:invoke) + + subject.restore(data) expect(output).to include("ERRORS") expect(output).not_to include(noise) expect(output).to include(visible_error) + expect(subject.post_restore_warning).not_to be_nil end end @@ -66,7 +95,9 @@ RSpec.describe Backup::Database do end it 'overrides default config values' do - subject.restore + expect(Rake::Task['gitlab:db:drop_tables']).to receive(:invoke) + + subject.restore(data) expect(output).to include(%("PGHOST"=>"test.example.com")) expect(output).to include(%("PGPASSWORD"=>"donotchange")) |