Sha256: 7044dcf5180eead349335b339e5e07e64c3338816d995b24323e35e4aeb5e821

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

describe Astrails::Safe::Mongodump do
  def def_config
    {
      :host => 'prod.example.com',
      :user => 'testuser',
      :password => 'p4ssw0rd',
    }
  end
  
  def mongodump(id = :foo, config = def_config)
    Astrails::Safe::Mongodump.new(id, Astrails::Safe::Config::Node.new(nil, config))
  end
  
  before(:each) do
    stub(Time).now.stub!.strftime {"NOW"}
    @output_folder = File.join(Astrails::Safe::TmpFile.tmproot, 'mongodump')
  end
  
  after(:each) { Astrails::Safe::TmpFile.cleanup }
  
  describe :backup do
    before(:each) do
      @mongo = mongodump
    end
    
    {
      :id => "foo",
      :kind => "mongodump",
      :extension => ".tar",
      :filename => "mongodump-foo.NOW"
    }.each do |k, v|
      it "should set #{k} to #{v}" do
        @mongo.backup.send(k).should == v
      end
    end
    
    it "should set the command" do
      @mongo.backup.send(:command).should == "mongodump -q \"{xxxx : { \\$ne : 0 } }\" --db foo --host prod.example.com -u testuser -p p4ssw0rd --out #{@output_folder} && cd #{@output_folder} && tar cf - ."
    end
    
    {
      :host => "--host ",
      :user => "-u ",
      :password => "-p "
    }.each do |key, v|    
      it "should not add #{key} to command if it is not present" do
        @mongo = mongodump(:foo, def_config.reject! {|k,v| k == key})
        @mongo.backup.send(:command).should_not =~ /#{v}/
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
akupchanko-astrails-safe-0.3.1 spec/astrails/safe/mongodump_spec.rb