=begin = myrds_spec.rb *Copyright*:: (C) 2013 by Novu, LLC *Author(s)*:: Tamara Temple *Since*:: 2013-05-01 *License*:: GPLv3 *Version*:: 0.0.1 == Description Test myrds.rb =end require 'spec_helper' require 'new_backup/myrds.rb' require 'fog' require 'date' module NewBackup describe MyRds do it {NewBackup::MyRds.should respond_to(:new)} describe "Operations" do it "#connect" do Fog.mock! options = { :aws => { :access_key => 'bogus access key', :secret_key => 'bogus secret key', :rds_region => 'us-east-1'}, :fog => { :timeout => 10 }, :timestamp => DateTime.now.iso8601 } NewBackup::MyRds.new(options).connect do |connection| connection.should_not be_nil end end it "#retrieve_snapshot" do Fog.mock! options = { :rds => { :instance_id => 'tamtest' }, :aws => { :access_key => 'bogus access key', :secret_key => 'bogus secret key', :rds_region => 'us-east-1'}, :fog => { :timeout => 10}, :timestamp => DateTime.now.iso8601 } rds_server = double('rds_server') snapshot = double('snapshot') rds_server.stub_chain(:snapshots, :new, :save) rds_server.stub_chain(:snapshots, :get) {snapshot} snapshot.stub(:wait_for) snapshot.stub(:destroy) NewBackup::MyRds.new(options).retrieve_snapshot(rds_server) do |snapshot| snapshot.should_not be_nil end end it "#restore_db" do Fog.mock! options = { :rds => { :instance_id => 'tamtest', :subnet_group => '', :instance_type => 'db.t1.micro' }, :aws => { :access_key => 'bogus access key', :secret_key => 'bogus secret key', :rds_region => 'us-east-1'}, :mysql => { :database => 'qadb', :username => 'root', :password => 'aaaa', :obfuscate_script => 'zzzz' }, :fog => { :timeout => 10 }, :timestamp => DateTime.now.iso8601 } connection = double('connection') snapshot = double('snapshot') backup_server = double('backup_server') connection.stub(:restore_db_instance_from_db_snapshot) connection.stub_chain(:servers, :get) {backup_server} snapshot.stub(:id) backup_server.stub_chain(:endpoint, :[]).with("Address").and_return("localhost") backup_server.stub(:wait_for) backup_server.stub(:destroy) NewBackup::MyRds.new(options).restore_db(connection, snapshot) do |db| db.should_not be_nil end end end describe "#snap_name" do let(:timestamp) {DateTime.now.iso8601} it {NewBackup::MyRds.new(:timestamp => timestamp).snap_name.should == "s3-dump-snap-#{timestamp}" } end end end