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

[ibm] Update tests to match model arguments (attribs hash) and lower-level request methods

This commit is contained in:
Decklin Foster 2012-02-13 10:03:00 -05:00
parent 1b44269e00
commit 02fc7a2232
10 changed files with 37 additions and 43 deletions

View file

@ -102,11 +102,11 @@ module Fog
}
end
def create_instance(name, image_id, instance_type, location, public_key, options)
def create_instance(name, image_id, instance_type, location, options)
{
"name" => name,
"location" => location,
"keyName" => public_key,
"keyName" => options[:key_name],
"primaryIP" => Fog::IBM::Mock.primary_ip,
"productCodes" => [],
"requestId" => Fog::IBM::Mock.request_id,

View file

@ -35,8 +35,8 @@ module Fog
class Mock
def create_address(location_id, offering_id="20001223", vlan_id=nil)
address = Fog::IBM::Mock.create_address(location_id, offering_id, vlan_id)
def create_address(location_id, offering_id="20001223", options={})
address = Fog::IBM::Mock.create_address(location_id, offering_id, options)
self.data[:addresses][address['id']] = address
response = Excon::Response.new
response.status = 200

View file

@ -10,8 +10,8 @@ module Fog
# * image_id<~String> - The id of the image to create this instance from
# * instance_type<~String> - The instance type to use for this instance
# * location<~String> - The id of the Location where this instance will be created
# * public_key<~String> - The public key to use for accessing the created instance
# * options<~Hash>:
# * :key_name<~String> - The public key to use for accessing the created instance
# * :ip<~String> - The ID of a static IP address to associate with this instance
# * :volume_id<~String> - The ID of a storage volume to associate with this instance
# * :vlan_id<~String> - The ID of a Vlan offering to associate with this instance.
@ -57,7 +57,7 @@ module Fog
class Mock
def create_instance(name="fog instance", image_id="20018425", instance_type="COP32.1/2048/60", location="101", public_key="fog", options={})
def create_instance(name, image_id, instance_type, location, options={})
response = Excon::Response.new
# Since we want to test error conditions, we have a little regex that traps specially formed
# instance type strings.
@ -65,7 +65,7 @@ module Fog
when /FAIL:\ (\d{3})/
response.status = $1
else
instance = Fog::IBM::Mock.create_instance(name, image_id, instance_type, location, public_key, options)
instance = Fog::IBM::Mock.create_instance(name, image_id, instance_type, location, options)
self.data[:instances][instance['id']] = instance
response.status = 200
response.body = {"instances" => [ instance ]}

View file

@ -5,8 +5,8 @@ Shindo.tests('Fog::Compute[:ibm] | keys', ['ibm']) do
@key_name = "fog test key"
@key = nil
tests("Fog::Compute[:ibm].keys.create('#{@key_name}')") do
@key = Fog::Compute[:ibm].keys.create(@key_name)
tests("Fog::Compute[:ibm].keys.create(:name => '#{@key_name}')") do
@key = Fog::Compute[:ibm].keys.create(:name => @key_name)
returns(@key_name) { @key.name }
end

View file

@ -2,7 +2,12 @@ Shindo.tests('Fog::Compute[:ibm] | servers', ['ibm']) do
tests('success') do
@instance_id = Fog::Compute[:ibm].create_instance.body["instances"][0]["id"]
@name = "fog-test-instance-" + Time.now.to_i.to_s(32)
@image_id = "20010001"
@instance_type = "BRZ32.1/2048/60*175"
@location_id = "41"
@instance_id = Fog::Compute[:ibm].create_instance(@name, @image_id, @instance_type, @location_id).body["instances"][0]["id"]
@server = nil
tests('Fog::Compute[:ibm].servers') do

View file

@ -23,7 +23,7 @@ Shindo.tests('Fog::Compute[:ibm] | address requests', ['ibm']) do
tests('success') do
tests("#create_address('#{@location_id}')").formats(@create_address_format) do
data = Fog::Compute[:ibm].create_address(@location_id).body
data = Fog::Compute[:ibm].create_address(@location_id, @offering_id).body
@address_id = data['id']
data
end

View file

@ -76,8 +76,7 @@ Shindo.tests('Fog::Compute[:ibm] | image requests', ['ibm']) do
@image_id,
@instance_type,
@location,
@public_key,
@options
:key_name => @public_key
).body
@instance_id = response['instances'][0]['id']
data = Fog::Compute[:ibm].create_image(@instance_id, @image_name, "").body

View file

@ -37,12 +37,11 @@ Shindo.tests('Fog::Compute[:ibm] | instance requests', ['ibm']) do
@image_id = "20018425"
@instance_type = "COP32.1/2048/60"
@location = "101"
@public_key = "test"
@expiration_time= (Time.now.tv_usec + 10000).to_f * 1000
@options = {}
@options = {:key_name => "test"}
tests("#create_instance('#{@name}', '#{@image_id}', '#{@instance_type}', '#{@location}', '#{@public_key}', options)").formats(@instances_format) do
response = Fog::Compute[:ibm].create_instance(@name, @image_id, @instance_type, @location, @public_key, @options).body
tests("#create_instance('#{@name}', '#{@image_id}', '#{@instance_type}', '#{@location}', #{@options})").formats(@instances_format) do
response = Fog::Compute[:ibm].create_instance(@name, @image_id, @instance_type, @location, @options).body
@instance_id = response['instances'][0]['id']
response
end
@ -57,16 +56,16 @@ Shindo.tests('Fog::Compute[:ibm] | instance requests', ['ibm']) do
instances = Fog::Compute[:ibm].list_instances.body
end
tests("#restart_instance('#{@instance_id}', '#{@public_key}')") do
returns(true) { Fog::Compute[:ibm].restart_instance(@instance_id, @public_key).body["success"] }
tests("#modify_instance('#{@instance_id}', 'state' => 'restart')") do
returns(true) { Fog::Compute[:ibm].modify_instance(@instance_id, 'state' => 'restart').body["success"] }
end
tests("#rename_instance('#{@instance_id}', '#{@name} 2')") do
returns(true) { Fog::Compute[:ibm].rename_instance(@instance_id, @name + " 2").body["success"] }
tests("#modify_instance('#{@instance_id}', 'name' => '#{@name} 2')") do
returns(true) { Fog::Compute[:ibm].modify_instance(@instance_id, 'name' => @name + " 2").body["success"] }
end
tests("#set_instance_expiration('#{@instance_id}', '#{@expiration_time}')") do
returns(@expiration_time) { Fog::Compute[:ibm].set_instance_expiration(@instance_id, @expiration_time).body["expirationTime"] }
tests("#modify_instance('#{@instance_id}', 'expirationTime' => '#{@expiration_time}')") do
returns(@expiration_time) { Fog::Compute[:ibm].modify_instance(@instance_id, 'expirationTime' => @expiration_time).body["expirationTime"] }
end
tests("#delete_instance('#{@instance_id}')") do
@ -78,7 +77,7 @@ Shindo.tests('Fog::Compute[:ibm] | instance requests', ['ibm']) do
tests('failures') do
tests('#create_instance => 401') do
response = Fog::Compute[:ibm].create_instance("FAIL: 401", "123456", "12345", "101", "invalid")
response = Fog::Compute[:ibm].create_instance("FAIL: 401", "123456", "12345", "101", :key_name => "invalid")
returns("401") { response.status }
end

View file

@ -28,6 +28,10 @@ Shindo.tests('Fog::Compute[:ibm] | key requests', ['ibm']) do
Fog::Compute[:ibm].create_key(@key_name).body
end
tests("#create_key('#{@key_name}', '#{@public_key}')").formats(@key_format) do
Fog::Compute[:ibm].create_key(@key_name, @public_key).body
end
tests("#list_keys").formats(@keys_format) do
Fog::Compute[:ibm].list_keys.body
end
@ -36,16 +40,8 @@ Shindo.tests('Fog::Compute[:ibm] | key requests', ['ibm']) do
Fog::Compute[:ibm].get_key(@key_name).body
end
tests("#set_default_key('#{@key_name}')") do
returns(@key_name) { Fog::Compute[:ibm].set_default_key(@key_name).body }
end
tests("#update_key('#{@key_name}', '#{@public_key}')") do
returns(true) { Fog::Compute[:ibm].update_key(@key_name, @public_key).body['success'] }
end
tests("#set_default_key('#{@key_name}')") do
returns(true) { Fog::Compute[:ibm].modify_key(@key_name, 'default' => true).body['success'] }
returns(@key_name) { Fog::Compute[:ibm].modify_key(@key_name, 'default' => true).body }
end
tests("#update_key('#{@key_name}', 'publicKey' => '#{@public_key}')") do
@ -56,10 +52,6 @@ Shindo.tests('Fog::Compute[:ibm] | key requests', ['ibm']) do
returns(true) { Fog::Compute[:ibm].delete_key(@key_name).body['success'] }
end
tests("#upload_key('#{@key_name}', '#{@public_key}')") do
returns(true) { Fog::Compute[:ibm].upload_key(@key_name, @public_key).body['success'] }
end
end
end

View file

@ -43,8 +43,8 @@ Shindo.tests('Fog::Compute[:ibm] | volume requests', ['ibm']) do
@location = "101"
@public_key = "test"
tests("#create_volume('#{@name}', '#{@format}', '#{@location_id}', '#{@size}', '#{@offering_id}')").formats(@volume_format) do
data = Fog::Compute[:ibm].create_volume(@name, @format, @location_id, @size, @offering_id).body
tests("#create_volume('#{@name}', '#{@offering_id}', '#{@format}', '#{@location_id}', '#{@size}')").formats(@volume_format) do
data = Fog::Storage[:ibm].create_volume(@name, @offering_id, @format, @location_id, @size).body
@volume_id = data['id']
data
end
@ -63,16 +63,15 @@ Shindo.tests('Fog::Compute[:ibm] | volume requests', ['ibm']) do
@image_id,
@instance_type,
@location,
@public_key,
@options
:key_name => @public_key
).body['instances'][0]['id']
# TODO: Add assertions for this whenever it is properly supported
Fog::Compute[:ibm].attach_volume(@instance_id, @volume_id)
Fog::Compute[:ibm].modify_instance(@instance_id, 'type' => 'attach', 'volume_id' => @volume_id)
end
tests("#detach_volume('#{@instance_id}','#{@volume_id}')") do
# TODO: Add assertions for this whenever it is properly supported
Fog::Compute[:ibm].detach_volume(@instance_id, @volume_id)
Fog::Compute[:ibm].modify_instance(@instance_id, 'type' => 'attach', 'volume_id' => @volume_id)
Fog::Compute[:ibm].delete_instance(@instance_id)
end