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:
parent
cc59a7a964
commit
1bde6e169a
2 changed files with 50 additions and 81 deletions
|
@ -1,6 +1,22 @@
|
|||
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
|
||||
|
||||
|
@ -17,27 +33,13 @@ describe 'Fog::AWS::EC2::Snapshots' do
|
|||
|
||||
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
|
||||
|
||||
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.wait_for { ready? }
|
||||
snapshot.destroy.should be_true
|
||||
volume.destroy
|
||||
@snapshot = @volume.snapshots.create
|
||||
@snapshot.wait_for { ready? }
|
||||
@snapshot.destroy.should be_true
|
||||
@snapshot = nil # avoid the after(:each) block
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -45,23 +47,13 @@ describe 'Fog::AWS::EC2::Snapshots' do
|
|||
describe "#reload" do
|
||||
|
||||
before(:each) do
|
||||
@volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
|
||||
@snapshot = @volume.snapshots.create
|
||||
@reloaded = @snapshot.reload
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@snapshot.wait_for { ready? }
|
||||
@snapshot.destroy
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::EC2::Snapshot" do
|
||||
it "should match the original" do
|
||||
@reloaded.should be_a(Fog::AWS::EC2::Snapshot)
|
||||
end
|
||||
|
||||
it "should reset attributes to remote state" do
|
||||
@snapshot.attributes.should == @reloaded.attributes
|
||||
@reloaded.attributes.should == @snapshot.attributes
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -69,30 +61,13 @@ describe 'Fog::AWS::EC2::Snapshots' do
|
|||
describe "#save" 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
|
||||
end
|
||||
|
||||
after(:each) 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
|
||||
it "should persist the snapshot" do
|
||||
AWS[:ec2].snapshots.get(@snapshot.id).should be_nil
|
||||
end
|
||||
|
||||
it "should exist in snapshots after save" do
|
||||
@snapshot.save
|
||||
@snapshot.save.should be_true
|
||||
AWS[:ec2].snapshots.get(@snapshot.id).should_not be_nil
|
||||
@snapshot.wait_for { ready? }
|
||||
@snapshot.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,31 +2,39 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
|
|||
|
||||
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
|
||||
|
||||
it "should return a Fog::AWS::EC2::Snapshots" do
|
||||
AWS[:ec2].snapshots.all.should be_a(Fog::AWS::EC2::Snapshots)
|
||||
before(:each) do
|
||||
@snapshot = @volume.snapshots.create
|
||||
end
|
||||
|
||||
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)
|
||||
@snapshot.destroy
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
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')
|
||||
@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? }
|
||||
@snapshot.destroy
|
||||
@volume.snapshots.map {|snapshot| snapshot.id}.should include(@snapshot.identity)
|
||||
@other_volume.snapshots.map {|snapshot| snapshot.id}.should_not include(@snapshot.identity)
|
||||
|
||||
@other_volume.destroy
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -34,21 +42,9 @@ describe 'Fog::AWS::EC2::Snapshots' do
|
|||
describe "#create" 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
|
||||
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
|
||||
AWS[:ec2].snapshots.get(@snapshot.id).should_not be_nil
|
||||
end
|
||||
|
@ -58,12 +54,10 @@ describe 'Fog::AWS::EC2::Snapshots' do
|
|||
describe "#get" 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.wait_for { ready? }
|
||||
get = AWS[:ec2].snapshots.get(snapshot.id)
|
||||
snapshot.attributes.should == get.attributes
|
||||
snapshot.destroy
|
||||
@snapshot = @volume.snapshots.create
|
||||
@snapshot.wait_for { ready? }
|
||||
get = AWS[:ec2].snapshots.get(@snapshot.id)
|
||||
@snapshot.attributes.should == get.attributes
|
||||
end
|
||||
|
||||
it "should return nil if no matching address exists" do
|
||||
|
|
Loading…
Reference in a new issue