2009-08-17 18:55:30 -04:00
|
|
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2009-07-17 03:36:42 -04:00
|
|
|
|
|
|
|
describe 'EC2.terminate_instances' do
|
2009-08-19 23:32:57 -04:00
|
|
|
describe 'success' do
|
2009-07-17 03:36:42 -04:00
|
|
|
|
2009-08-19 23:32:57 -04:00
|
|
|
before(:each) do
|
|
|
|
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId']
|
|
|
|
end
|
2009-07-17 03:36:42 -04:00
|
|
|
|
2009-08-19 23:32:57 -04:00
|
|
|
it "should return proper attributes" do
|
2009-08-22 01:04:12 -04:00
|
|
|
actual = ec2.terminate_instances(@instance_id)
|
2009-08-19 23:32:57 -04:00
|
|
|
actual.body['requestId'].should be_a(String)
|
|
|
|
actual.body['instancesSet'].should be_an(Array)
|
|
|
|
instance = actual.body['instancesSet'].select {|instance| instance['instanceId'] == @instance_id}.first
|
|
|
|
instance['previousState'].should be_a(Hash)
|
|
|
|
previous_state = instance['previousState']
|
|
|
|
previous_state['code'].should be_a(Integer)
|
|
|
|
previous_state['name'].should be_a(String)
|
|
|
|
instance['shutdownState'].should be_a(Hash)
|
|
|
|
shutdown_state = instance['shutdownState']
|
|
|
|
shutdown_state['code'].should be_a(Integer)
|
|
|
|
shutdown_state['name'].should be_a(String)
|
|
|
|
end
|
2009-07-17 03:36:42 -04:00
|
|
|
|
2009-08-19 23:32:57 -04:00
|
|
|
end
|
2009-08-22 01:04:12 -04:00
|
|
|
describe 'failure' do
|
|
|
|
|
|
|
|
it 'should raise a BadRequest error if the instance does not exist' do
|
|
|
|
lambda {
|
|
|
|
ec2.terminate_instances('i-00000000')
|
|
|
|
}.should raise_error(Fog::Errors::BadRequest)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-17 03:36:42 -04:00
|
|
|
end
|