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

fixes/specs for security_group(s)

This commit is contained in:
Wesley Beary 2009-09-28 20:00:49 -07:00
parent 830a9907fd
commit eadd0231a7
5 changed files with 160 additions and 3 deletions

View file

@ -30,6 +30,8 @@ module Fog
load "fog/aws/models/ec2/addresses.rb"
load "fog/aws/models/ec2/key_pair.rb"
load "fog/aws/models/ec2/key_pairs.rb"
load "fog/aws/models/ec2/security_group.rb"
load "fog/aws/models/ec2/security_groups.rb"
load "fog/aws/models/ec2/snapshot.rb"
load "fog/aws/models/ec2/snapshots.rb"
load "fog/aws/models/ec2/volume.rb"

View file

@ -15,12 +15,12 @@ module Fog
end
def reload
new_attributes = security_groups.all(@public_ip).first.attributes
new_attributes = security_groups.get(@group_name).attributes
merge_attributes(new_attributes)
end
def save
data = connection.create_create_security_group(@group_name, @group_description).body
data = connection.create_security_group(@group_name, @group_description).body
true
end

View file

@ -16,7 +16,7 @@ module Fog
end
def all(group_name = [])
data = connection.describe_security_groups(group_name)
data = connection.describe_security_groups(group_name).body
security_groups = Fog::AWS::EC2::SecurityGroups.new({
:connection => connection,
:group_name => group_name

View file

@ -0,0 +1,84 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::SecurityGroup' do
describe "#initialize" do
it "should remap attributes from parser" #do
# address = Fog::AWS::EC2::SecurityGroup.new(
# 'instanceId' => 'i-00000000',
# 'publicIp' => '0.0.0.0'
# )
# address.instance_id.should == 'i-00000000'
# address.public_ip.should == '0.0.0.0'
# end
end
describe "#security_groups" do
it "should return a Fog::AWS::EC2::SecurityGroups" do
ec2.security_groups.new.security_groups.should be_a(Fog::AWS::EC2::SecurityGroups)
end
it "should be the security_groups the keypair is related to" do
security_groups = ec2.security_groups
security_groups.new.security_groups.should == security_groups
end
end
describe "#destroy" do
it "should return true if the security_group is deleted" do
address = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname')
address.destroy.should be_true
end
end
describe "#reload" do
before(:each) do
@security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname')
@reloaded = @security_group.reload
end
after(:each) do
@security_group.destroy
end
it "should return a Fog::AWS::EC2::SecurityGroup" do
@reloaded.should be_a(Fog::AWS::EC2::SecurityGroup)
end
it "should reset attributes to remote state" do
@security_group.attributes.should == @reloaded.attributes
end
end
describe "#save" do
before(:each) do
@security_group = ec2.security_groups.new(:group_description => 'groupdescription', :group_name => 'keyname')
end
it "should return true when it succeeds" do
@security_group.save.should be_true
@security_group.destroy
end
it "should not exist in security_groups before save" do
@security_group.security_groups.get(@security_group.group_name).should be_nil
end
it "should exist in buckets after save" do
@security_group.save
@security_group.security_groups.get(@security_group.group_name).should_not be_nil
@security_group.destroy
end
end
end

View file

@ -0,0 +1,71 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::SecurityGroups' do
describe "#all" do
it "should return a Fog::AWS::EC2::SecurityGroups" do
ec2.security_groups.all.should be_a(Fog::AWS::EC2::SecurityGroups)
end
it "should include persisted security_groups" do
security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname')
ec2.security_groups.get(security_group.group_name).should_not be_nil
security_group.destroy
end
end
describe "#create" do
before(:each) do
@security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname')
end
after(:each) do
@security_group.destroy
end
it "should return a Fog::AWS::EC2::SecurityGroup" do
@security_group.should be_a(Fog::AWS::EC2::SecurityGroup)
end
it "should exist on ec2" do
ec2.security_groups.get(@security_group.group_name).should_not be_nil
end
end
describe "#get" do
it "should return a Fog::AWS::EC2::SecurityGroup if a matching security_group exists" do
security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname')
get = ec2.security_groups.get(security_group.group_name)
security_group.attributes[:fingerprint].should == get.attributes[:fingerprint]
security_group.attributes[:group_name].should == get.attributes[:group_name]
security_group.destroy
end
it "should return nil if no matching security_group exists" do
ec2.security_groups.get('notasecuritygroupname').should be_nil
end
end
describe "#new" do
it "should return a Fog::AWS::EC2::SecurityGroup" do
ec2.security_groups.new(:group_description => 'groupdescription', :group_name => 'keyname').should be_a(Fog::AWS::EC2::SecurityGroup)
end
end
describe "#reload" do
it "should return a Fog::AWS::EC2::SecurityGroups" do
ec2.security_groups.all.reload.should be_a(Fog::AWS::EC2::SecurityGroups)
end
end
end