#--
# Amazon Web Services EC2 Query API Ruby library, EBS snapshots support
#
# Ruby Gem Name:: amazon-ec2
# Author:: Yann Klis (mailto:yann.klis@novelys.com)
# Copyright:: Copyright (c) 2008 Yann Klis
# License:: Distributes under the same terms as Ruby
# Home:: http://github.com/grempe/amazon-ec2/tree/master
#++
require File.dirname(__FILE__) + '/test_helper.rb'
context "EC2 snaphots " do
setup do
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
@describe_snapshots_response_body = <<-RESPONSE
snap-78a54011
vol-4d826724
pending
2008-05-07T12:51:50.000Z
RESPONSE
@create_snapshot_response_body = <<-RESPONSE
snap-78a54011
vol-4d826724
pending
2008-05-07T12:51:50.000Z
RESPONSE
@delete_snapshot_response_body = <<-RESPONSE
true
RESPONSE
end
specify "should be able to be described with describe_snapshots" do
@ec2.stubs(:make_request).with('DescribeSnapshots', {"SnapshotId.1"=>"snap-78a54011"}).
returns stub(:body => @describe_snapshots_response_body, :is_a? => true)
@ec2.describe_snapshots( :snapshot_id => "snap-78a54011" ).should.be.an.instance_of Hash
response = @ec2.describe_snapshots( :snapshot_id => "snap-78a54011" )
response.snapshotId.should.equal "snap-78a54011"
response.volumeId.should.equal "vol-4d826724"
response.status.should.equal "pending"
response.progress.should.equal "80%"
end
specify "should be able to be created with a volume_id" do
@ec2.stubs(:make_request).with('CreateSnapshot', {"VolumeId" => "vol-4d826724"}).
returns stub(:body => @create_snapshot_response_body, :is_a? => true)
@ec2.create_snapshot( :volume_id => "vol-4d826724" ).should.be.an.instance_of Hash
response = @ec2.create_snapshot( :volume_id => "vol-4d826724" )
response.snapshotId.should.equal "snap-78a54011"
response.volumeId.should.equal "vol-4d826724"
response.status.should.equal "pending"
response.progress.should.equal nil
end
specify "should be able to be deleted with a snapsot_id" do
@ec2.stubs(:make_request).with('DeleteSnapshot', {"SnapshotId" => "snap-78a54011"}).
returns stub(:body => @delete_snapshot_response_body, :is_a? => true)
@ec2.delete_snapshot( :snapshot_id => "snap-78a54011" ).should.be.an.instance_of Hash
response = @ec2.delete_snapshot( :snapshot_id => "snap-78a54011" )
response.return.should.equal "true"
end
end