1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/spec/aws/requests/ec2/describe_instances_spec.rb

87 lines
3.9 KiB
Ruby
Raw Normal View History

2009-08-17 18:55:30 -04:00
require File.dirname(__FILE__) + '/../../../spec_helper'
2009-07-06 23:45:16 -04:00
2009-07-09 00:58:02 -04:00
describe 'EC2.describe_instances' do
2009-08-19 23:32:57 -04:00
describe 'success' do
2009-07-06 23:45:16 -04:00
2009-08-19 23:32:57 -04:00
before(:each) do
run_instances = ec2.run_instances('ami-5ee70037', 1, 1).body
@instance_id = run_instances['instancesSet'].first['instanceId']
@reservation_id = run_instances['reservationId']
end
2009-08-19 23:32:57 -04:00
after(:each) do
ec2.terminate_instances([@instance_id])
end
2009-08-19 23:32:57 -04:00
it "should return proper attributes with no params" do
actual = ec2.describe_instances
reservation = actual.body['reservationSet'].select {|reservation| reservation['reservationId'] == @reservation_id}.first
reservation['groupSet'].should be_an(Array)
reservation['groupSet'].first.should be_a(String)
reservation['ownerId'].should be_a(String)
reservation['reservationId'].should be_a(String)
instance = reservation['instancesSet'].select {|instance| instance['instanceId'] == @instance_id}.first
instance['amiLaunchIndex'].should be_an(Integer)
instance['dnsName'].should be_a(String)
instance['imageId'].should be_a(String)
instance['instanceId'].should be_a(String)
instance['instanceState'].should be_a(Hash)
instance['instanceState']['code'].should be_a(Integer)
2009-08-19 23:32:57 -04:00
instance['instanceState']['name'].should be_a(String)
instance['instanceType'].should be_a(String)
instance['kernelId'].should be_a(String)
instance['keyName'].should be_a(String) if instance['keyName']
instance['launchTime'].should be_a(Time)
instance['monitoring'].should be_a(Hash)
[true, false].should include(instance['monitoring']['state'])
instance['placement'].should be_a(Hash)
instance['placement']['availabilityZone'].should be_a(String)
2009-08-19 23:32:57 -04:00
instance['privateDnsName'].should be_a(String)
instance['productCodes'].should be_an(Array)
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
instance['ramdiskId'].should be_a(String)
instance['reason'].should be_a(String)
end
2009-07-06 23:45:16 -04:00
2009-08-19 23:32:57 -04:00
it "should return proper attributes with params" do
actual = ec2.describe_instances(@instance_id)
reservation = actual.body['reservationSet'].select {|reservation| reservation['reservationId'] == @reservation_id}.first
reservation['groupSet'].should be_an(Array)
reservation['groupSet'].first.should be_a(String)
reservation['ownerId'].should be_a(String)
reservation['reservationId'].should be_a(String)
instance = reservation['instancesSet'].select {|instance| instance['instanceId'] == @instance_id}.first
instance['amiLaunchIndex'].should be_an(Integer)
instance['dnsName'].should be_a(String)
instance['imageId'].should be_a(String)
instance['instanceId'].should be_a(String)
instance['instanceState'].should be_a(Hash)
instance['instanceState']['code'].should be_a(Integer)
2009-08-19 23:32:57 -04:00
instance['instanceState']['name'].should be_a(String)
instance['instanceType'].should be_a(String)
instance['kernelId'].should be_a(String)
instance['keyName'].should be_a(String) if instance['keyName']
instance['launchTime'].should be_a(Time)
instance['monitoring'].should be_a(Hash)
[true, false].should include(instance['monitoring']['state'])
instance['placement'].should be_a(Hash)
instance['placement']['availabilityZone'].should be_a(String)
2009-08-19 23:32:57 -04:00
instance['privateDnsName'].should be_a(String)
instance['productCodes'].should be_an(Array)
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
instance['ramdiskId'].should be_a(String)
instance['reason'].should be_a(String)
end
2009-07-06 23:45:16 -04:00
2009-08-19 23:32:57 -04:00
end
describe 'failure' do
it 'should raise a BadRequest error if the instance does not exist' do
lambda {
ec2.describe_instances('i-00000000')
}.should raise_error(Fog::Errors::BadRequest)
end
end
2009-07-06 23:45:16 -04:00
end