From 1e4c61c265a90dd55df0466a0916e41811b6cc03 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Wed, 19 Aug 2009 19:11:40 -0700 Subject: [PATCH] spec snapshot failure cases --- spec/aws/requests/ec2/create_snapshot_spec.rb | 47 ++++++++++++------- spec/aws/requests/ec2/delete_snapshot_spec.rb | 39 +++++++++------ .../requests/ec2/describe_snapshot_spec.rb | 6 +++ 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/spec/aws/requests/ec2/create_snapshot_spec.rb b/spec/aws/requests/ec2/create_snapshot_spec.rb index 3e78e34d1..c446da5ae 100644 --- a/spec/aws/requests/ec2/create_snapshot_spec.rb +++ b/spec/aws/requests/ec2/create_snapshot_spec.rb @@ -1,26 +1,37 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe 'EC2.create_snapshot' do + describe "success" do - before(:all) do - @volume_id = ec2.create_volume('us-east-1a', 1).body['volumeId'] - end - - after(:all) do - ec2.delete_volume(@volume_id) - eventually do - ec2.delete_snapshot(@snapshot_id) + before(:all) do + @volume_id = ec2.create_volume('us-east-1a', 1).body['volumeId'] end - end - it "should return proper attributes" do - actual = ec2.create_snapshot(@volume_id) - actual.body['progress'].should be_a(String) - @snapshot_id = actual.body['snapshotId'] - actual.body['snapshotId'].should be_a(String) - actual.body['startTime'].should be_a(Time) - actual.body['status'].should be_a(String) - actual.body['volumeId'].should be_a(String) - end + after(:all) do + ec2.delete_volume(@volume_id) + eventually do + ec2.delete_snapshot(@snapshot_id) + end + end + it "should return proper attributes" do + actual = ec2.create_snapshot(@volume_id) + actual.body['progress'].should be_a(String) + @snapshot_id = actual.body['snapshotId'] + actual.body['snapshotId'].should be_a(String) + actual.body['startTime'].should be_a(Time) + actual.body['status'].should be_a(String) + actual.body['volumeId'].should be_a(String) + end + + end + describe "failure" do + + it "should raise a BadRequest error if the volume does not exist" do + lambda { + ec2.create_snapshot('vol-00000000') + }.should raise_error(Fog::Errors::BadRequest) + end + + end end diff --git a/spec/aws/requests/ec2/delete_snapshot_spec.rb b/spec/aws/requests/ec2/delete_snapshot_spec.rb index 2cddfff20..72eb9c13f 100644 --- a/spec/aws/requests/ec2/delete_snapshot_spec.rb +++ b/spec/aws/requests/ec2/delete_snapshot_spec.rb @@ -1,24 +1,35 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe 'EC2.delete_snapshot' do + describe 'success' do - before(:all) do - @volume_id = ec2.create_volume('us-east-1a', 1).body['volumeId'] - @snapshot_id = ec2.create_snapshot(@volume_id).body['snapshotId'] - end + before(:all) do + @volume_id = ec2.create_volume('us-east-1a', 1).body['volumeId'] + @snapshot_id = ec2.create_snapshot(@volume_id).body['snapshotId'] + end - after(:all) do - ec2.delete_volume(@volume_id) - end + after(:all) do + ec2.delete_volume(@volume_id) + end - it "should return proper attributes" do - eventually do - actual = ec2.delete_snapshot(@snapshot_id) - unless actual.body.empty? - actual.body['requestId'].should be_a(String) - [false, true].should include(actual.body['return']) + it "should return proper attributes" do + eventually do + actual = ec2.delete_snapshot(@snapshot_id) + unless actual.body.empty? + actual.body['requestId'].should be_a(String) + [false, true].should include(actual.body['return']) + end end end - end + end + describe 'failure' do + + it "should raise a BadRequest error if snapshot does not exist" do + lambda { + ec2.release_address('snap-00000000') + }.should raise_error(Fog::Errors::BadRequest) + end + + end end diff --git a/spec/aws/requests/ec2/describe_snapshot_spec.rb b/spec/aws/requests/ec2/describe_snapshot_spec.rb index 7bf5ea623..753bd7657 100644 --- a/spec/aws/requests/ec2/describe_snapshot_spec.rb +++ b/spec/aws/requests/ec2/describe_snapshot_spec.rb @@ -40,4 +40,10 @@ describe 'EC2.describe_snapshots' do end end + it "should raise a BadRequest error if the snapshot does not exist" do + lambda { + ec2.describe_snapshots('snap-00000000') + }.should raise_error(Fog::Errors::BadRequest) + end + end