Sha256: 277d68d9d034678c1682a5b547c87ffc761edd007da9e6ecc5844d475dff2d72

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../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

4 entries across 4 versions & 2 rubygems

Version Path
astrails-safe-0.3.1 spec/unit/mongodump_spec.rb
netguru-safe-0.2.11 spec/unit/mongodump_spec.rb
netguru-safe-0.2.10 spec/unit/mongodump_spec.rb
netguru-safe-0.2.9 spec/unit/mongodump_spec.rb