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

[ec2] simplify/dry snapshot(s) specs

This commit is contained in:
geemus 2010-04-28 14:39:31 -07:00
parent cc59a7a964
commit 1bde6e169a
2 changed files with 50 additions and 81 deletions

View file

@ -1,6 +1,22 @@
require File.dirname(__FILE__) + '/../../../spec_helper' require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::Snapshots' do describe 'Fog::AWS::EC2::Snapshot' do
before(:all) do
@volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
@volume.wait_for { ready? }
end
after(:all) do
@volume.destroy
end
after(:each) do
if @snapshot && !@snapshot.new_record?
@snapshot.wait_for { ready? }
@snapshot.destroy
end
end
describe "#initialize" do describe "#initialize" do
@ -17,27 +33,13 @@ describe 'Fog::AWS::EC2::Snapshots' do
end end
describe "#collection" do
it "should return a Fog::AWS::EC2::Snapshots" do
AWS[:ec2].snapshots.new.collection.should be_a(Fog::AWS::EC2::Snapshots)
end
it "should be the snapshots the snapshot is related to" do
snapshots = AWS[:ec2].snapshots
snapshots.new.collection.should == snapshots
end
end
describe "#destroy" do describe "#destroy" do
it "should return true if the snapshot is deleted" do it "should return true if the snapshot is deleted" do
volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') @snapshot = @volume.snapshots.create
snapshot = volume.snapshots.create @snapshot.wait_for { ready? }
snapshot.wait_for { ready? } @snapshot.destroy.should be_true
snapshot.destroy.should be_true @snapshot = nil # avoid the after(:each) block
volume.destroy
end end
end end
@ -45,23 +47,13 @@ describe 'Fog::AWS::EC2::Snapshots' do
describe "#reload" do describe "#reload" do
before(:each) do before(:each) do
@volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
@snapshot = @volume.snapshots.create @snapshot = @volume.snapshots.create
@reloaded = @snapshot.reload @reloaded = @snapshot.reload
end end
after(:each) do it "should match the original" do
@snapshot.wait_for { ready? }
@snapshot.destroy
@volume.destroy
end
it "should return a Fog::AWS::EC2::Snapshot" do
@reloaded.should be_a(Fog::AWS::EC2::Snapshot) @reloaded.should be_a(Fog::AWS::EC2::Snapshot)
end @reloaded.attributes.should == @snapshot.attributes
it "should reset attributes to remote state" do
@snapshot.attributes.should == @reloaded.attributes
end end
end end
@ -69,30 +61,13 @@ describe 'Fog::AWS::EC2::Snapshots' do
describe "#save" do describe "#save" do
before(:each) do before(:each) do
@volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
@volume.wait_for { ready? }
@snapshot = @volume.snapshots.new @snapshot = @volume.snapshots.new
end end
after(:each) do it "should persist the snapshot" do
@volume.destroy
end
it "should return true when it succeeds" do
@snapshot.save.should be_true
@snapshot.wait_for { ready? }
@snapshot.destroy
end
it "should not exist in snapshots before save" do
AWS[:ec2].snapshots.get(@snapshot.id).should be_nil AWS[:ec2].snapshots.get(@snapshot.id).should be_nil
end @snapshot.save.should be_true
it "should exist in snapshots after save" do
@snapshot.save
AWS[:ec2].snapshots.get(@snapshot.id).should_not be_nil AWS[:ec2].snapshots.get(@snapshot.id).should_not be_nil
@snapshot.wait_for { ready? }
@snapshot.destroy
end end
end end

View file

@ -2,31 +2,39 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::Snapshots' do describe 'Fog::AWS::EC2::Snapshots' do
before(:all) do
@volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
@volume.wait_for { ready? }
end
after(:all) do
@volume.destroy
end
after(:each) do
if @snapshot && !@snapshot.new_record?
@snapshot.wait_for { ready? }
@snapshot.destroy
end
end
describe "#all" do describe "#all" do
it "should return a Fog::AWS::EC2::Snapshots" do before(:each) do
AWS[:ec2].snapshots.all.should be_a(Fog::AWS::EC2::Snapshots) @snapshot = @volume.snapshots.create
end end
it "should include persisted snapshots" do it "should include persisted snapshots" do
@volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
eventually { @snapshot = @volume.snapshots.create }
AWS[:ec2].snapshots.all.map {|snapshot| snapshot.id}.should include(@snapshot.id) AWS[:ec2].snapshots.all.map {|snapshot| snapshot.id}.should include(@snapshot.id)
@snapshot.destroy
@volume.destroy
end end
it "should limit snapshots by volume if present" do it "should limit snapshots by volume if present" do
@volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
@other_volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') @other_volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
@volume.wait_for { ready?}
@snapshot = @volume.snapshots.create
@other_volume.snapshots.all.map {|snapshot| snapshot.id}.should_not include(@snapshot.id)
@snapshot.wait_for { ready? } @volume.snapshots.map {|snapshot| snapshot.id}.should include(@snapshot.identity)
@snapshot.destroy @other_volume.snapshots.map {|snapshot| snapshot.id}.should_not include(@snapshot.identity)
@other_volume.destroy @other_volume.destroy
@volume.destroy
end end
end end
@ -34,21 +42,9 @@ describe 'Fog::AWS::EC2::Snapshots' do
describe "#create" do describe "#create" do
before(:each) do before(:each) do
@volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
@volume.wait_for { ready? }
@snapshot = @volume.snapshots.create @snapshot = @volume.snapshots.create
end end
after(:each) do
@snapshot.wait_for { ready? }
@snapshot.destroy
@volume.destroy
end
it "should return a Fog::AWS::EC2::Snapshot" do
@snapshot.should be_a(Fog::AWS::EC2::Snapshot)
end
it "should exist on ec2" do it "should exist on ec2" do
AWS[:ec2].snapshots.get(@snapshot.id).should_not be_nil AWS[:ec2].snapshots.get(@snapshot.id).should_not be_nil
end end
@ -58,12 +54,10 @@ describe 'Fog::AWS::EC2::Snapshots' do
describe "#get" do describe "#get" do
it "should return a Fog::AWS::EC2::Snapshot if a matching snapshot exists" do it "should return a Fog::AWS::EC2::Snapshot if a matching snapshot exists" do
volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') @snapshot = @volume.snapshots.create
snapshot = volume.snapshots.create @snapshot.wait_for { ready? }
snapshot.wait_for { ready? } get = AWS[:ec2].snapshots.get(@snapshot.id)
get = AWS[:ec2].snapshots.get(snapshot.id) @snapshot.attributes.should == get.attributes
snapshot.attributes.should == get.attributes
snapshot.destroy
end end
it "should return nil if no matching address exists" do it "should return nil if no matching address exists" do