Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 64 lines (54 sloc) 2.522 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#--
# Amazon Web Services EC2 Query API Ruby library
#
# Ruby Gem Name:: amazon-ec2
# Author:: Glenn Rempe (mailto:glenn@rempe.us)
# Copyright:: Copyright (c) 2007-2010 Glenn Rempe
# License:: Distributes under the same terms as Ruby
# Home:: http://github.com/grempe/amazon-ec2/tree/master
#++

require File.dirname(__FILE__) + '/test_helper.rb'

context "The EC2 subnets " do

  before do
    @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )

    @describe_subnets_response_body = <<-RESPONSE
<DescribeSubnetsResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01">
<subnetSet>
<item>
<state>available</state>
<availableIpAddressCount>251</availableIpAddressCount>
<subnetId>subnet-000000e0</subnetId>
<cidrBlock>10.225.251.0/24</cidrBlock>
<vpcId>vpc-b00000db</vpcId>
<availabilityZone>us-east-1a</availabilityZone>
</item>
<item>
<state>available</state>
<availableIpAddressCount>251</availableIpAddressCount>
<subnetId>subnet-11111!e1</subnetId>
<cidrBlock>10.225.251.0/24</cidrBlock>
<vpcId>vpc-b00000db</vpcId>
<availabilityZone>us-east-1a</availabilityZone>
</item>
</subnetSet>
</DescribeSubnetsResponse>
RESPONSE

  end


  specify "should be able to be described with no params and return a subnetSet" do
    @ec2.stubs(:make_request).with('DescribeSubnets', {}).
      returns stub(:body => @describe_subnets_response_body, :is_a? => true)
    @ec2.describe_subnets.subnetSet.item.length.should.equal 2
  end


  specify "should be able to be described with describe_subnet" do
    @ec2.stubs(:make_request).with('DescribeSubnets', {"SubnetId.1"=>"subnet-000000e0"}).
      returns stub(:body => @describe_subnets_response_body, :is_a? => true)
    @ec2.describe_subnets( :subnet_id => "subnet-000000e0" ).should.be.an.instance_of Hash
    response = @ec2.describe_subnets( :subnet_id => "subnet-000000e0" )
    response.subnetSet.item[0].state.should.equal "available"
    response.subnetSet.item[0].availableIpAddressCount.should.equal "251"
    response.subnetSet.item[0].subnetId.should.equal "subnet-000000e0"
    response.subnetSet.item[0].cidrBlock.should.equal "10.225.251.0/24"
    response.subnetSet.item[0].vpcId.should.equal "vpc-b00000db"
    response.subnetSet.item[0].availabilityZone.should.equal "us-east-1a"
  end

end
Something went wrong with that request. Please try again.