Navigation Menu

Skip to content
This repository has been archived by the owner on Jan 20, 2019. It is now read-only.

Commit

Permalink
fix tests for new register_image params
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespharaoh committed Mar 26, 2010
1 parent 9b4712f commit 34049a5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
30 changes: 16 additions & 14 deletions lib/AWS/EC2/images.rb
Expand Up @@ -56,20 +56,22 @@ def deregister_image( options = {} )
#
def register_image( options = {} )
params = {}
params["ImageLocation"] = options[:image_location].to_s
params["Name"] = options[:name].to_s
params["Description"] = options[:description].to_s
params["Architecture"] = options[:architecture].to_s
params["KernelId"] = options[:kernel_id].to_s
params["RamdiskId"] = options[:ramdisk_id].to_s
params["RootDeviceName"] = options[:root_device_name].to_s
params.merge!(pathhashlist("BlockDeviceMapping", options[:block_device_mapping].flatten, {
:device_name => "DeviceName",
:virtual_name => "VirtualName",
:ebs_snapshot_id => "Ebs.SnapshotId",
:ebs_volume_size => "Ebs.VolumeSize",
:ebs_delete_on_termination => "Ebs.DeleteOnTermination"
}))
params["ImageLocation"] = options[:image_location].to_s unless options[:image_location].nil?
params["Name"] = options[:name].to_s unless options[:name].nil?
params["Description"] = options[:description].to_s unless options[:description].nil?
params["Architecture"] = options[:architecture].to_s unless options[:architecture].nil?
params["KernelId"] = options[:kernel_id].to_s unless options[:kernel_id].nil?
params["RamdiskId"] = options[:ramdisk_id].to_s unless options[:ramdisk_id].nil?
params["RootDeviceName"] = options[:root_device_name].to_s unless options[:root_device_name].nil?
if options[:block_device_mapping]
params.merge!(pathhashlist("BlockDeviceMapping", options[:block_device_mapping].flatten, {
:device_name => "DeviceName",
:virtual_name => "VirtualName",
:ebs_snapshot_id => "Ebs.SnapshotId",
:ebs_volume_size => "Ebs.VolumeSize",
:ebs_delete_on_termination => "Ebs.DeleteOnTermination"
}))
end
return response_generator(:action => "RegisterImage", :params => params)
end

Expand Down
30 changes: 26 additions & 4 deletions test/test_EC2_images.rb
Expand Up @@ -88,17 +88,39 @@
end


specify "should be able to be registered" do
specify "should be able to be registered with manifest" do
@ec2.stubs(:make_request).with('RegisterImage', {"ImageLocation"=>"mybucket-myimage.manifest.xml"}).
returns stub(:body => @register_image_response_body, :is_a? => true)
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").imageId.should.equal "ami-61a54008"
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").should.be.an.instance_of Hash
end


specify "method register_image should raise an exception when called without nil/empty string arguments" do
lambda { @ec2.register_image() }.should.raise(AWS::ArgumentError)
lambda { @ec2.register_image(:image_location => "") }.should.raise(AWS::ArgumentError)
specify "should be able to be registered with snapshot" do
@ec2.stubs(:make_request).with('RegisterImage', {
"Name" => "image_name",
"Architecture" => "i386",
"KernelId" => "aki-01234567",
"RamdiskId" => "ari-01234567",
"RootDeviceName" => "/dev/sda1",
"BlockDeviceMapping.1.DeviceName" => "/dev/sda1",
"BlockDeviceMapping.1.Ebs.SnapshotId" => "snap-01234567",
"BlockDeviceMapping.1.Ebs.DeleteOnTermination" => "true",
}).returns stub(:body => @register_image_response_body, :is_a? => true)
ret = @ec2.register_image({
:name => "image_name",
:architecture => "i386",
:kernel_id => "aki-01234567",
:ramdisk_id => "ari-01234567",
:root_device_name => "/dev/sda1",
:block_device_mapping => [{
:device_name => "/dev/sda1",
:ebs_snapshot_id => "snap-01234567",
:ebs_delete_on_termination => true,
}]
})
ret.imageId.should.equal "ami-61a54008"
ret.should.be.an.instance_of Hash
end


Expand Down

0 comments on commit 34049a5

Please sign in to comment.