backup_rake_spec.rb 1.59 KB
Newer Older
Hugo Duksis's avatar
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's avatar
Hugo Duksis committed
7
    Rake.application.rake_require "tasks/gitlab/backup"
Andrew Kumanyaev's avatar
Andrew Kumanyaev committed
8
    Rake.application.rake_require "tasks/gitlab/shell"
Hugo Duksis's avatar
Hugo Duksis committed
9 10 11 12 13 14 15 16 17 18 19
    # 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's avatar
Dmitriy Zaporozhets committed
20 21
      Rake::Task["gitlab:backup:restore"].reenable
      Rake.application.invoke_task "gitlab:backup:restore"
Hugo Duksis's avatar
Hugo Duksis committed
22 23 24 25
    end

    context 'gitlab version' do
      before do
26
        Dir.stub glob: []
27
        Dir.stub :chdir
28 29
        File.stub exists?: true
        Kernel.stub system: true
Andrew Kumanyaev's avatar
Andrew Kumanyaev committed
30 31 32
        FileUtils.stub cp_r: true
        FileUtils.stub mv: true
        Rake::Task["gitlab:shell:setup"].stub invoke: true
Hugo Duksis's avatar
Hugo Duksis committed
33 34 35 36
      end

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

Johannes Schleifenbaum's avatar
Johannes Schleifenbaum committed
37
      it 'should fail on mismatch' do
38
        YAML.stub load_file: {gitlab_version: gitlab_version.reverse}
Hugo Duksis's avatar
Hugo Duksis committed
39 40 41 42
        expect { run_rake_task }.to raise_error SystemExit
      end

      it 'should invoke restoration on mach' do
43
        YAML.stub load_file: {gitlab_version: gitlab_version}
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
44 45
        Rake::Task["gitlab:backup:db:restore"].should_receive :invoke
        Rake::Task["gitlab:backup:repo:restore"].should_receive :invoke
Andrew Kumanyaev's avatar
Andrew Kumanyaev committed
46 47
        Rake::Task["gitlab:shell:setup"].should_receive :invoke
        expect { run_rake_task }.to_not raise_error
Hugo Duksis's avatar
Hugo Duksis committed
48 49 50 51 52
      end
    end

  end # backup_restore task
end # gitlab:app namespace