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

first pass at instance model spec

This commit is contained in:
Wesley Beary 2009-10-08 23:01:09 -07:00
parent 4bab2f4e7a
commit c2d58e493d
5 changed files with 199 additions and 7 deletions

View file

@ -27,6 +27,10 @@ def buckets
@s3.buckets
end
def instances
@ec2.instances
end
def key_pairs
@ec2.key_pairs
end

View file

@ -28,6 +28,8 @@ module Fog
load "fog/aws/models/ec2/address.rb"
load "fog/aws/models/ec2/addresses.rb"
load "fog/aws/models/ec2/instance.rb"
load "fog/aws/models/ec2/instances.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"

View file

@ -10,16 +10,24 @@ module Fog
attribute :instance_id
def initialize(attributes)
@instance_id ||= []
super
end
def all(instance_id = [])
data = connection.describe_instances(instance_id)
data = connection.describe_instances(instance_id).body
instances = Fog::AWS::EC2::Instances.new({
:connection => connection
:connection => connection,
:instance_id => instance_id
}.merge!(attributes))
data['instancesSet'].each do |instance|
instances << Fog::AWS::EC2::Instances.new({
:connection => connection,
:instances => self
}.merge!(instance))
data['reservationSet'].each do |reservation|
reservation['instancesSet'].each do |instance|
instances << Fog::AWS::EC2::Instance.new({
:connection => connection,
:instances => self
}.merge!(instance))
end
end
instances
end

View file

@ -0,0 +1,108 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::Instance' do
describe "#initialize" do
it "should remap attributes from parser" # do
# instance = Fog::AWS::EC2::Instance.new(
# 'instanceId' => 'i-00000000',
# 'publicIp' => '0.0.0.0'
# )
# instance.instance_id.should == 'i-00000000'
# instance.public_ip.should == '0.0.0.0'
# end
end
describe "#address" do
it "should have tests"
end
describe "#destroy" do
it "should return true if the instance is deleted" do
instance = ec2.instances.create(:image_id => 'ami-5ee70037')
instance.destroy.should be_true
end
end
describe "#instances" do
it "should return a Fog::AWS::EC2::Instances" do
ec2.instances.new.instances.should be_a(Fog::AWS::EC2::Instances)
end
it "should be the instances the instance is related to" do
instances = ec2.instances
instances.new.instances.should == instances
end
end
describe "#key_pair" do
it "should have tests"
end
describe "#key_pair=" do
it "should have tests"
end
describe "#monitoring=" do
it "should have tests"
end
describe "#placement=" do
it "should have tests"
end
describe "#reload" do
before(:each) do
@instance = ec2.instances.create(:image_id => 'ami-5ee70037')
@reloaded = @instance.reload
end
after(:each) do
@instance.destroy
end
it "should return a Fog::AWS::EC2::Instance" do
@reloaded.should be_a(Fog::AWS::EC2::Instance)
end
it "should reset attributes to remote state" do
@instance.attributes.should == @reloaded.attributes
end
end
describe "#save" do
before(:each) do
@instance = ec2.instances.new
end
it "should return true when it succeeds" do
@instance.save.should be_true
@instance.destroy
end
it "should not exist in instances before save" do
@instance.instances.get(@instance.instance_id).should be_nil
end
it "should exist in buckets after save" do
@instance.save
@instance.instances.get(@instance.instance_id).should_not be_nil
@instance.destroy
end
end
describe "#volumes" do
it "should have tests"
end
end

View file

@ -0,0 +1,70 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::Instances' do
describe "#all" do
it "should return a Fog::AWS::EC2::Instances" do
ec2.instances.all.should be_a(Fog::AWS::EC2::Instances)
end
it "should include persisted instances" do
instance = ec2.instances.create(:image_id => 'ami-5ee70037')
ec2.instances.get(instance.instance_id).should_not be_nil
instance.destroy
end
end
describe "#create" do
before(:each) do
@instance = ec2.instances.create(:image_id => 'ami-5ee70037')
end
after(:each) do
@instance.destroy
end
it "should return a Fog::AWS::EC2::Instance" do
@instance.should be_a(Fog::AWS::EC2::Instance)
end
it "should exist on ec2" do
ec2.instances.get(@instance.instance_id).should_not be_nil
end
end
describe "#get" do
it "should return a Fog::AWS::EC2::Instance if a matching instance exists" do
instance = ec2.instances.create(:image_id => 'ami-5ee70037')
get = ec2.instances.get(instance.instance_id)
instance.attributes.should == get.attributes
instance.destroy
end
it "should return nil if no matching instance exists" do
ec2.instances.get('i-00000000').should be_nil
end
end
describe "#new" do
it "should return a Fog::AWS::EC2::Instance" do
ec2.instances.new(:image_id => 'ami-5ee70037').should be_a(Fog::AWS::EC2::Instance)
end
end
describe "#reload" do
it "should return a Fog::AWS::EC2::Instances" do
ec2.instances.all.reload.should be_a(Fog::AWS::EC2::Instances)
end
end
end