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/models/compute/volume_spec.rb

175 lines
4.8 KiB
Ruby
Raw Normal View History

2011-01-10 14:12:48 +08:00
require 'spec_helper'
2009-09-23 21:23:54 -07:00
2010-09-09 17:50:38 -07:00
describe 'Fog::AWS::Compute::Volume' do
2009-09-23 21:23:54 -07:00
describe "#initialize" do
2009-10-06 20:35:46 -07:00
it "should remap attributes from parser" do
2010-09-09 17:50:38 -07:00
volume = AWS[:compute].volumes.new(
'attachTime' => 'now',
2009-10-06 20:35:46 -07:00
'availabilityZone' => 'us-east-1a',
'createTime' => 'recently',
'instanceId' => 'i-00000000',
'snapshotId' => 'snap-00000000',
'volumeId' => 'vol-00000000'
)
volume.attached_at.should == 'now'
2009-10-06 20:35:46 -07:00
volume.availability_zone.should == 'us-east-1a'
volume.created_at.should == 'recently'
2010-01-08 11:29:07 -08:00
volume.server_id.should == 'i-00000000'
2009-10-06 20:35:46 -07:00
volume.snapshot_id.should == 'snap-00000000'
volume.id.should == 'vol-00000000'
2009-10-06 20:35:46 -07:00
end
2009-09-23 21:23:54 -07:00
end
describe "#collection" do
2009-09-23 21:23:54 -07:00
2010-09-09 17:50:38 -07:00
it "should return a Fog::AWS::Compute::Volumes" do
AWS[:compute].volumes.new.collection.should be_a(Fog::AWS::Compute::Volumes)
2009-09-23 21:23:54 -07:00
end
it "should be the volumes the volume is related to" do
2010-09-09 17:50:38 -07:00
volumes = AWS[:compute].volumes
volumes.new.collection.should == volumes
2009-09-23 21:23:54 -07:00
end
end
describe "#destroy" do
it "should return true if the volume is deleted" do
2010-09-09 17:50:38 -07:00
volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
2009-09-23 21:23:54 -07:00
volume.destroy.should be_true
end
it 'should fail if the volume is attached to an instance' do
2010-09-09 17:50:38 -07:00
server = AWS[:compute].servers.create(:image_id => GENTOO_AMI)
server.wait_for { ready? }
2010-09-09 17:50:38 -07:00
volume = AWS[:compute].volumes.create(:availability_zone => server.availability_zone, :size => 1, :device => '/dev/sdz1')
volume.server = server
lambda { volume.destroy }.should raise_error
end
2009-09-23 21:23:54 -07:00
end
2010-01-08 11:29:07 -08:00
describe "#server=" do
before(:all) do
2010-09-09 17:50:38 -07:00
@server = AWS[:compute].servers.create(:image_id => GENTOO_AMI)
2010-04-28 11:00:01 -07:00
@server.wait_for { ready? }
end
after(:all) do
2010-01-08 11:29:07 -08:00
@server.destroy
end
before(:each) do
2010-09-09 17:50:38 -07:00
@volume = AWS[:compute].volumes.new(:availability_zone => @server.availability_zone, :size => 1, :device => '/dev/sdz1')
end
describe "when set to a server" do
after(:each) do
if @volume.id
@volume.wait_for { state == 'in-use' }
@volume.server = nil
@volume.wait_for { ready? }
@volume.destroy
end
end
it "should not attach to server if the volume has not been saved" do
@volume.server = @server
@volume.server_id.should_not == @server.id
end
it "should change the availability_zone if the volume has not been saved" do
@volume.server = @server
@volume.availability_zone.should == @server.availability_zone
end
it "should attach to server when the volume is saved" do
@volume.server = @server
@volume.save.should be_true
@volume.server_id.should == @server.id
end
it "should attach to server to an already saved volume" do
@volume.save.should be_true
@volume.server = @server
@volume.server_id.should == @server.id
end
it "should not change the availability_zone if the volume has been saved" do
@volume.save.should be_true
@volume.server = @server
@volume.availability_zone.should == @server.availability_zone
end
end
describe "when set to nil" do
after(:each) do
@volume.destroy
end
it "should detach from server if the volume has been saved" do
@volume.server = @server
@volume.save.should be_true
@server.reload.volumes.map(&:id).should include(@volume.id)
@volume.server = nil
@volume.wait_for { ready? }
@volume.server_id.should be_nil
@server.reload.volumes.map(&:id).should_not include(@volume.id)
end
end
end
2009-09-23 21:23:54 -07:00
describe "#reload" do
before(:each) do
2010-09-09 17:50:38 -07:00
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
2009-09-23 21:23:54 -07:00
@reloaded = @volume.reload
end
after(:each) do
@volume.destroy
end
2010-09-09 17:50:38 -07:00
it "should return a Fog::AWS::Compute::Volume" do
@reloaded.should be_a(Fog::AWS::Compute::Volume)
2009-09-23 21:23:54 -07:00
end
it "should reset attributes to remote state" do
@volume.attributes.should == @reloaded.attributes
end
end
describe "#save" do
before(:each) do
2010-09-09 17:50:38 -07:00
@volume = AWS[:compute].volumes.new(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
2009-09-23 21:23:54 -07:00
end
it "should return true when it succeeds" do
@volume.save.should be_true
@volume.destroy
end
it "should not exist in volumes before save" do
2010-09-09 17:50:38 -07:00
AWS[:compute].volumes.get(@volume.id).should be_nil
2009-09-23 21:23:54 -07:00
end
it "should exist in buckets after save" do
@volume.save
2010-09-09 17:50:38 -07:00
AWS[:compute].volumes.get(@volume.id).should_not be_nil
2009-09-23 21:23:54 -07:00
@volume.destroy
end
end
end