1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

spec work

- move specs for instance= off instance to address/volume and implement
- use a constant, rather than a magic string, for ami reference
- add test for model instance#placement=
This commit is contained in:
Wesley Beary 2009-10-22 09:42:02 -07:00
parent a87cb036fa
commit 84179b4d5b
17 changed files with 108 additions and 35 deletions

View file

@ -42,7 +42,7 @@ module Fog
data = connection.allocate_address
@public_ip = data.body['publicIp']
if @instance
instance = @instance
self.instance = @instance
end
true
end

View file

@ -46,7 +46,7 @@ module Fog
new_attributes = data.reject {|key,value| key == 'requestId'}
merge_attributes(new_attributes)
if @instance
instance = @instance
self.instance = @instance
end
true
end

View file

@ -37,6 +37,37 @@ describe 'Fog::AWS::EC2::Address' do
end
describe "#instance=" do
before(:each) do
@address = ec2.addresses.new
@instance = ec2.instances.create(:image_id => GENTOO_AMI)
end
after(:each) do
if @address.public_ip
@address.destroy
end
@instance.destroy
end
it "should not associate with instance if the address has not been saved" do
@address.instance = @instance
@address.instance_id.should_not == @instance.instance_id
end
it "should associate with instance when the address is saved" do
@address.instance = @instance
@address.save.should be_true
@address.instance_id.should == @instance.instance_id
end
it "should associate with instance to an already saved address" do
@address.save.should be_true
@address.instance = @instance
@address.instance_id.should == @instance.instance_id
end
end
describe "#reload" do
before(:each) do

View file

@ -11,23 +11,19 @@ describe 'Fog::AWS::EC2::Instance' do
'groupId' => 'group_id',
'imageId' => 'image_id',
'instanceId' => 'instance_id',
'instanceState' => { 'name' => 'instance_state' },
'instanceType' => 'instance_type',
'kernelId' => 'kernel_id',
'keyName' => 'key_name',
'launchTime' => 'launch_time',
'placement' => { 'availabilityZone' => 'availability_zone'},
'productCodes' => 'product_codes',
'privateDnsName' => 'private_dns_name',
'ramdiskId' => 'ramdisk_id'
})
instance.ami_launch_index.should == 'ami_launch_index'
instance.availability_zone.should == 'availability_zone'
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_state.should == 'instance_state'
instance.instance_type.should == 'instance_type'
instance.kernel_id.should == 'kernel_id'
instance.key_name.should == 'key_name'
@ -46,21 +42,26 @@ describe 'Fog::AWS::EC2::Instance' do
instance.addresses.should be_a(Fog::AWS::EC2::Addresses)
end
it "should not associate the address to a not yet saved instance"
it "should associate the address after saving a new instance"
it "should associate the address to an existing instance"
end
describe "#destroy" do
it "should return true if the instance is deleted" do
instance = ec2.instances.create(:image_id => 'ami-5ee70037')
instance = ec2.instances.create(:image_id => GENTOO_AMI)
instance.destroy.should be_true
end
end
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
describe "#instances" do
it "should return a Fog::AWS::EC2::Instances" do
@ -83,17 +84,29 @@ describe 'Fog::AWS::EC2::Instance' do
end
describe "#monitoring=" do
it "should have tests"
it "should remap values out of hash" do
instance = Fog::AWS::EC2::Instance.new({
'monitoring' => { 'state' => true }
})
instance.monitoring.should == true
end
end
describe "#placement=" do
it "should have tests"
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
end
describe "#reload" do
before(:each) do
@instance = ec2.instances.create(:image_id => 'ami-5ee70037')
@instance = ec2.instances.create(:image_id => GENTOO_AMI)
@reloaded = @instance.reload
end
@ -141,10 +154,6 @@ describe 'Fog::AWS::EC2::Instance' do
instance.volumes.should be_a(Fog::AWS::EC2::Volumes)
end
it "should not attach the volume to a not yet saved instance"
it "should attach the volume after saving a new instance"
it "should attach the volume to an existing instance"
end
end

View file

@ -9,7 +9,7 @@ describe 'Fog::AWS::EC2::Instances' do
end
it "should include persisted instances" do
instance = ec2.instances.create(:image_id => 'ami-5ee70037')
instance = ec2.instances.create(:image_id => GENTOO_AMI)
ec2.instances.get(instance.instance_id).should_not be_nil
instance.destroy
end
@ -19,7 +19,7 @@ describe 'Fog::AWS::EC2::Instances' do
describe "#create" do
before(:each) do
@instance = ec2.instances.create(:image_id => 'ami-5ee70037')
@instance = ec2.instances.create(:image_id => GENTOO_AMI)
end
after(:each) do
@ -39,7 +39,7 @@ describe 'Fog::AWS::EC2::Instances' do
describe "#get" do
it "should return a Fog::AWS::EC2::Instance if a matching instance exists" do
instance = ec2.instances.create(:image_id => 'ami-5ee70037')
instance = ec2.instances.create(:image_id => GENTOO_AMI)
get = ec2.instances.get(instance.instance_id)
instance.attributes.should == get.attributes
instance.destroy
@ -54,7 +54,7 @@ describe 'Fog::AWS::EC2::Instances' do
describe "#new" do
it "should return a Fog::AWS::EC2::Instance" do
ec2.instances.new(:image_id => 'ami-5ee70037').should be_a(Fog::AWS::EC2::Instance)
ec2.instances.new(:image_id => GENTOO_AMI).should be_a(Fog::AWS::EC2::Instance)
end
end

View file

@ -45,6 +45,37 @@ describe 'Fog::AWS::EC2::Volume' do
end
describe "#instance=" do
before(:each) do
@volume = ec2.volumes.new
@instance = ec2.instances.create(:image_id => GENTOO_AMI)
end
after(:each) do
if @volume.volume_id
@volume.destroy
end
@instance.destroy
end
it "should not attach to instance if the address has not been saved" do
@volume.instance = @instance
@volume.instance_id.should_not == @instance.instance_id
end
it "should attach to instance when the address is saved" do
@volume.instance = @instance
@volume.save.should be_true
@volume.instance_id.should == @instance.instance_id
end
it "should attach to instance to an already saved address" do
@volume.save.should be_true
@volume.instance = @instance
@volume.instance_id.should == @instance.instance_id
end
end
describe "#reload" do
before(:each) do

View file

@ -4,7 +4,7 @@ describe 'EC2.associate_address' do
describe 'success' do
before(:each) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
@public_ip = ec2.allocate_address.body['publicIp']
end
@ -31,7 +31,7 @@ describe 'EC2.associate_address' do
end
it "should raise a BadRequest error if the address does not exist" do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
lambda {
ec2.associate_address(@instance_id, '127.0.0.1')
}.should raise_error(Fog::Errors::BadRequest)

View file

@ -4,7 +4,7 @@ describe 'EC2.attach_volume' do
describe 'success' do
before(:each) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1, {'Placement.AvailabilityZone' => 'us-east-1a'}).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1, {'Placement.AvailabilityZone' => 'us-east-1a'}).body['instancesSet'].first['instanceId']
@volume_id = ec2.create_volume('us-east-1a', 1).body['volumeId']
end
@ -42,7 +42,7 @@ describe 'EC2.attach_volume' do
end
it "should raise a BadRequest error if the address does not exist" do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
lambda {
ec2.attach_volume(@instance_id, 'vol-00000000', '/dev/sdh')
}.should raise_error(Fog::Errors::BadRequest)

View file

@ -20,7 +20,7 @@ describe 'EC2.describe_images' do
end
it "should return proper attributes with params" do
actual = ec2.describe_images('ImageId' => 'ami-5ee70037')
actual = ec2.describe_images('ImageId' => GENTOO_AMI)
actual.body['requestId'].should be_a(String)
image = actual.body['imagesSet'].first
image['architecture'].should be_a(String)

View file

@ -4,7 +4,7 @@ describe 'EC2.describe_instances' do
describe 'success' do
before(:each) do
run_instances = ec2.run_instances('ami-5ee70037', 1, 1).body
run_instances = ec2.run_instances(GENTOO_AMI, 1, 1).body
@instance_id = run_instances['instancesSet'].first['instanceId']
@reservation_id = run_instances['reservationId']
end

View file

@ -4,7 +4,7 @@ describe 'EC2.detach_volume' do
describe 'success' do
before(:each) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1, {'Placement.AvailabilityZone' => 'us-east-1a'}).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1, {'Placement.AvailabilityZone' => 'us-east-1a'}).body['instancesSet'].first['instanceId']
@volume_id = ec2.create_volume('us-east-1a', 1).body['volumeId']
eventually(128) do
ec2.attach_volume(@instance_id, @volume_id, '/dev/sdh')

View file

@ -4,7 +4,7 @@ describe 'EC2.disassociate_address' do
describe 'success' do
before(:each) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
@public_ip = ec2.allocate_address.body['publicIp']
ec2.associate_address(@instance_id, @public_ip)
end

View file

@ -4,7 +4,7 @@ describe 'EC2.get_console_output' do
describe 'success' do
before(:each) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
end
after(:each) do

View file

@ -4,7 +4,7 @@ describe 'EC2.reboot_instances' do
describe 'success' do
before(:each) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
end
after(:each) do

View file

@ -9,7 +9,7 @@ describe 'EC2.run_instances' do
it "should return proper attributes" do
# ami-5ee70037 = gentoo
actual = ec2.run_instances('ami-5ee70037', 1, 1)
actual = ec2.run_instances(GENTOO_AMI, 1, 1)
@instance_id = actual.body['instancesSet'].first['instanceId']
actual.body['groupSet'].should be_an(Array)
actual.body['groupSet'].first.should be_a(String)

View file

@ -4,7 +4,7 @@ describe 'EC2.terminate_instances' do
describe 'success' do
before(:each) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId']
@instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
end
it "should return proper attributes" do

View file

@ -78,4 +78,6 @@ def eventually(max_delay = 16, &block)
raise error if delay >= max_delay
end
end
end
end
GENTOO_AMI = 'ami-5ee70037'