summaryrefslogtreecommitdiff
path: root/spec/lib/backup/database_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/lib/backup/database_spec.rb
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
downloadgitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/lib/backup/database_spec.rb')
-rw-r--r--spec/lib/backup/database_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/lib/backup/database_spec.rb b/spec/lib/backup/database_spec.rb
new file mode 100644
index 00000000000..fccd6db0018
--- /dev/null
+++ b/spec/lib/backup/database_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Backup::Database do
+ let(:progress) { StringIO.new }
+ let(:output) { progress.string }
+
+ 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 }
+
+ subject { described_class.new(progress, filename: data) }
+
+ before do
+ allow(subject).to receive(:pg_restore_cmd).and_return(cmd)
+ 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
+ expect(subject.restore).to eq([])
+
+ expect(output).to include("Restoring PostgreSQL database")
+ expect(output).to include("[DONE]")
+ expect(output).not_to include("ERRORS")
+ end
+ end
+
+ context 'with a corrupted .gz file' 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)
+ end
+ end
+
+ context 'when the restore command prints errors' do
+ let(:visible_error) { "This is a test error\n" }
+ let(:noise) { "Table projects does not exist\nmust be owner of extension pg_trgm\n" }
+ let(:cmd) { %W[#{Gem.ruby} -e $stderr.write("#{noise}#{visible_error}")] }
+
+ it 'filters out noise from errors' do
+ expect(subject.restore).to eq([visible_error])
+ expect(output).to include("ERRORS")
+ expect(output).not_to include(noise)
+ expect(output).to include(visible_error)
+ end
+ end
+ end
+end