File: test_EC2_spot_prices.rb

package info (click to toggle)
ruby-amazon-ec2 0.9.17-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,232 kB
  • sloc: ruby: 4,659; makefile: 5
file content (59 lines) | stat: -rw-r--r-- 2,554 bytes parent folder | download | duplicates (5)
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
require File.dirname(__FILE__) + '/test_helper.rb'

context "Spot price history " do

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

    @describe_spot_price_history_response_body = <<-RESPONSE
    <DescribeSpotPriceHistoryResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
      <spotPriceHistorySet>
        <item>
          <instanceType>m1.small</instanceType>
          <productDescription>Linux/UNIX</productDescription>
          <spotPrice>0.287</spotPrice>
          <timestamp>2009-12-04T20:56:05.000Z</timestamp>
        </item>
        <item>
          <instanceType>m1.small</instanceType>
          <productDescription>Windows</productDescription>
          <spotPrice>0.033</spotPrice>
          <timestamp>2009-12-04T22:33:47.000Z</timestamp>
        </item>
      </spotPriceHistorySet>
    </DescribeSpotPriceHistoryResponse>
    RESPONSE
  end

  specify "should be able to be listed" do
    @ec2.stubs(:make_request).with('DescribeSpotPriceHistory', {}).
      returns stub(:body => @describe_spot_price_history_response_body, :is_a? => true)
    @ec2.describe_spot_price_history().should.be.an.instance_of Hash
    @ec2.describe_spot_price_history().spotPriceHistorySet.item.should.be.an.instance_of Array
  end

  specify "should reject a start_time which is not a Time object" do
    lambda { @ec2.describe_spot_price_history(:start_time => "foo") }.should.raise(AWS::ArgumentError)
  end

  specify "should reject an end_time which is not a Time object" do
    lambda { @ec2.describe_spot_price_history(:end_time => 42) }.should.raise(AWS::ArgumentError)
  end

  specify "should be able to be requested with various instance types" do
    ["t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "c1.medium", "c1.xlarge", "m2.2xlarge", "m2.4xlarge", "cc1.4xlarge"].each do |type|
      @ec2.stubs(:make_request).with('DescribeSpotPriceHistory', {'InstanceType' => type}).
        returns stub(:body => @describe_spot_price_history_response_body, :is_a? => true)
      lambda { @ec2.describe_spot_price_history( :instance_type => type ) }.should.not.raise(AWS::ArgumentError)
    end
  end

  specify "should reject an invalid instance type" do
    lambda { @ec2.describe_spot_price_history(:instance_type => 'm1.tiny') }.should.raise(AWS::ArgumentError)
  end

  specify "should reject an invalid product description" do
    lambda { @ec2.describe_spot_price_history(:product_description => 'Solaris') }.should.raise(AWS::ArgumentError)
  end

end