BigW Consortium Gitlab

backup_rake_spec.rb 1.36 KB
Newer Older
Hugo Duksis committed
1 2 3 4 5
require 'spec_helper'
require 'rake'

describe 'gitlab:app namespace rake task' do
  before :all do
6
    Rake.application.rake_require "tasks/gitlab/task_helpers"
Hugo Duksis committed
7 8 9 10 11 12 13 14 15 16 17 18
    Rake.application.rake_require "tasks/gitlab/backup"
    # empty task as env is already loaded
    Rake::Task.define_task :environment
  end

  describe 'backup_restore' do
    before do
      # avoid writing task output to spec progress
      $stdout.stub :write
    end

    let :run_rake_task do
Dmitriy Zaporozhets committed
19 20
      Rake::Task["gitlab:backup:restore"].reenable
      Rake.application.invoke_task "gitlab:backup:restore"
Hugo Duksis committed
21 22 23 24
    end

    context 'gitlab version' do
      before do
25
        Dir.stub glob: []
26
        Dir.stub :chdir
27 28
        File.stub exists?: true
        Kernel.stub system: true
Hugo Duksis committed
29 30 31 32
      end

      let(:gitlab_version) { %x{git rev-parse HEAD}.gsub(/\n/,"") }

Johannes Schleifenbaum committed
33
      it 'should fail on mismatch' do
34
        YAML.stub load_file: {gitlab_version: gitlab_version.reverse}
Hugo Duksis committed
35 36 37 38
        expect { run_rake_task }.to raise_error SystemExit
      end

      it 'should invoke restoration on mach' do
39
        YAML.stub load_file: {gitlab_version: gitlab_version}
Dmitriy Zaporozhets committed
40 41
        Rake::Task["gitlab:backup:db:restore"].should_receive :invoke
        Rake::Task["gitlab:backup:repo:restore"].should_receive :invoke
Hugo Duksis committed
42 43 44 45 46 47
        expect { run_rake_task }.to_not raise_error SystemExit
      end
    end

  end # backup_restore task
end # gitlab:app namespace