Welcome to mirror list, hosted at ThFree Co, Russian Federation.

postgres_spec.rb « dump « backup « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f6a68ab6db9560568bdcca4e674581fd60b9b7de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Backup::Dump::Postgres, feature_category: :backup_restore do
  describe '#dump' do
    let(:pg_database) { 'gitlabhq_test' }
    let(:destination_dir) { Dir.mktmpdir }
    let(:db_file_name) { File.join(destination_dir, 'output.gz') }

    let(:pipes) { IO.pipe }
    let(:gzip_pid) { spawn('gzip -c -1', in: pipes[0], out: [db_file_name, 'w', 0o600]) }
    let(:pg_dump_pid) { Process.spawn('pg_dump', *args, pg_database, out: pipes[1]) }
    let(:args) { ['--help'] }

    subject { described_class.new }

    before do
      allow(IO).to receive(:pipe).and_return(pipes)
    end

    after do
      FileUtils.remove_entry destination_dir
    end

    it 'creates gzipped dump using supplied arguments' do
      expect(subject).to receive(:spawn).with('gzip -c -1', in: pipes.first,
                                                            out: [db_file_name, 'w', 0o600]).and_return(gzip_pid)
      expect(Process).to receive(:spawn).with('pg_dump', *args, pg_database, out: pipes[1]).and_return(pg_dump_pid)

      subject.dump(pg_database, db_file_name, args)

      expect(File.exist?(db_file_name)).to eq(true)
    end
  end
end