2009-10-08 23:01:09 -07:00
|
|
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
|
|
|
|
|
|
describe 'Fog::AWS::EC2::Instance' do
|
|
|
|
|
|
|
|
describe "#initialize" do
|
|
|
|
|
2009-10-09 22:54:17 -07:00
|
|
|
it "should remap attributes from parser" do
|
|
|
|
instance = Fog::AWS::EC2::Instance.new({
|
|
|
|
'amiLaunchIndex' => 'ami_launch_index',
|
|
|
|
'dnsName' => 'dns_name',
|
|
|
|
'groupId' => 'group_id',
|
|
|
|
'imageId' => 'image_id',
|
|
|
|
'instanceId' => 'instance_id',
|
|
|
|
'instanceType' => 'instance_type',
|
|
|
|
'kernelId' => 'kernel_id',
|
|
|
|
'keyName' => 'key_name',
|
|
|
|
'launchTime' => 'launch_time',
|
|
|
|
'productCodes' => 'product_codes',
|
|
|
|
'privateDnsName' => 'private_dns_name',
|
|
|
|
'ramdiskId' => 'ramdisk_id'
|
|
|
|
})
|
|
|
|
instance.ami_launch_index.should == 'ami_launch_index'
|
|
|
|
instance.dns_name.should == 'dns_name'
|
|
|
|
instance.group_id.should == 'group_id'
|
|
|
|
instance.image_id.should == 'image_id'
|
|
|
|
instance.instance_id.should == 'instance_id'
|
|
|
|
instance.instance_type.should == 'instance_type'
|
|
|
|
instance.kernel_id.should == 'kernel_id'
|
|
|
|
instance.key_name.should == 'key_name'
|
|
|
|
instance.launch_time.should == 'launch_time'
|
|
|
|
instance.product_codes.should == 'product_codes'
|
|
|
|
instance.private_dns_name.should == 'private_dns_name'
|
|
|
|
instance.ramdisk_id.should == 'ramdisk_id'
|
|
|
|
end
|
2009-10-08 23:01:09 -07:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2009-10-20 19:39:57 -07:00
|
|
|
describe "#addresses" do
|
|
|
|
|
|
|
|
it "should return a Fog::AWS::EC2::Addresses" do
|
|
|
|
instance = ec2.instances.new
|
|
|
|
instance.addresses.should be_a(Fog::AWS::EC2::Addresses)
|
|
|
|
end
|
|
|
|
|
2009-10-08 23:01:09 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#destroy" do
|
|
|
|
|
|
|
|
it "should return true if the instance is deleted" do
|
2009-10-22 09:42:02 -07:00
|
|
|
instance = ec2.instances.create(:image_id => GENTOO_AMI)
|
2009-10-08 23:01:09 -07:00
|
|
|
instance.destroy.should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2009-10-22 09:42:02 -07:00
|
|
|
describe "#instance_state" do
|
|
|
|
it "should remap values out of hash" do
|
|
|
|
instance = Fog::AWS::EC2::Instance.new({
|
|
|
|
'instanceState' => { 'name' => 'instance_state' },
|
|
|
|
})
|
|
|
|
instance.instance_state.should == 'instance_state'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-23 22:23:55 -07:00
|
|
|
describe "#collection" do
|
2009-10-08 23:01:09 -07:00
|
|
|
|
|
|
|
it "should return a Fog::AWS::EC2::Instances" do
|
2009-10-23 22:23:55 -07:00
|
|
|
ec2.instances.new.collection.should be_a(Fog::AWS::EC2::Instances)
|
2009-10-08 23:01:09 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be the instances the instance is related to" do
|
|
|
|
instances = ec2.instances
|
2009-10-23 22:23:55 -07:00
|
|
|
instances.new.collection.should == instances
|
2009-10-08 23:01:09 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#key_pair" do
|
|
|
|
it "should have tests"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#key_pair=" do
|
|
|
|
it "should have tests"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#monitoring=" do
|
2009-10-22 09:42:02 -07:00
|
|
|
it "should remap values out of hash" do
|
|
|
|
instance = Fog::AWS::EC2::Instance.new({
|
|
|
|
'monitoring' => { 'state' => true }
|
|
|
|
})
|
|
|
|
instance.monitoring.should == true
|
|
|
|
end
|
2009-10-08 23:01:09 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#placement=" do
|
2009-10-22 09:42:02 -07:00
|
|
|
|
|
|
|
it "should remap values into availability_zone" do
|
|
|
|
instance = Fog::AWS::EC2::Instance.new({
|
|
|
|
'placement' => { 'availabilityZone' => 'availability_zone' }
|
|
|
|
})
|
|
|
|
instance.availability_zone.should == 'availability_zone'
|
|
|
|
end
|
|
|
|
|
2009-10-08 23:01:09 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#reload" do
|
|
|
|
|
|
|
|
before(:each) do
|
2009-10-22 09:42:02 -07:00
|
|
|
@instance = ec2.instances.create(:image_id => GENTOO_AMI)
|
2009-10-08 23:01:09 -07:00
|
|
|
@reloaded = @instance.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
@instance.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return a Fog::AWS::EC2::Instance" do
|
|
|
|
@reloaded.should be_a(Fog::AWS::EC2::Instance)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should reset attributes to remote state" do
|
|
|
|
@instance.attributes.should == @reloaded.attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#save" do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@instance = ec2.instances.new
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true when it succeeds" do
|
|
|
|
@instance.save.should be_true
|
|
|
|
@instance.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not exist in instances before save" do
|
2009-10-23 22:23:55 -07:00
|
|
|
ec2.instances.get(@instance.instance_id).should be_nil
|
2009-10-08 23:01:09 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should exist in buckets after save" do
|
|
|
|
@instance.save
|
2009-10-23 22:23:55 -07:00
|
|
|
ec2.instances.get(@instance.instance_id).should_not be_nil
|
2009-10-08 23:01:09 -07:00
|
|
|
@instance.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#volumes" do
|
2009-10-09 22:54:17 -07:00
|
|
|
|
|
|
|
it "should return a Fog::AWS::EC2::Volumes" do
|
|
|
|
instance = ec2.instances.new
|
|
|
|
instance.volumes.should be_a(Fog::AWS::EC2::Volumes)
|
|
|
|
end
|
|
|
|
|
2009-10-08 23:01:09 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|