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

[brightbox] Added Server request tests

This commit is contained in:
Paul Thornthwaite 2010-12-01 13:07:39 +00:00
parent ebacb66e48
commit 2468c43df8
3 changed files with 168 additions and 2 deletions

View file

@ -0,0 +1,108 @@
class Brightbox
module Compute
module Formats
module Nested
SERVER_TYPE = {
"name" => String,
"cores" => Integer,
"created_at" => String,
"resource_type" => String,
"updated_at" => String,
"disk_size" => Integer,
"default" => Fog::Boolean,
"url" => String,
"id" => String,
"ram" => Integer,
"status" => String
}
ZONE = {
"handle" => String,
"resource_type" => String,
"url" => String,
"id" => String
}
ACCOUNT = {
"name" => String,
"ram_used" => Integer,
"resource_type" => String,
"ram_limit" => Integer,
"url" => String,
"id" => String,
"status" => String,
"limits_cloudips" => Integer
}
INTERFACE = {
"resource_type" => String,
"url" => String,
"id" => String,
"ipv4_address" => String,
"mac_address" => String
}
IMAGE = {
"name" => String,
"created_at" => String,
"resource_type" => String,
"arch" => String,
"url" => String,
"id" => String,
"description" => String,
"source" => String,
"status" => String,
"owner" => String
}
end
module Full
SERVER = {
'id' => String,
'resource_type' => String,
'url' => String,
'name' => String,
'status' => String,
'hostname' => String,
'created_at' => String,
'started_at' => NilClass,
'deleted_at' => NilClass,
'user_data' => NilClass,
'account' => Brightbox::Compute::Formats::Nested::ACCOUNT,
'server_type' => Brightbox::Compute::Formats::Nested::SERVER_TYPE,
'cloud_ips' => [],
'image' => Brightbox::Compute::Formats::Nested::IMAGE,
'snapshots' => [],
'interfaces' => [Brightbox::Compute::Formats::Nested::INTERFACE],
'zone' => Brightbox::Compute::Formats::Nested::ZONE
}
end
module Collected
SERVER = {
'id' => String,
'resource_type' => String,
'url' => String,
'name' => String,
'status' => String,
'hostname' => String,
'created_at' => String,
'started_at' => NilClass,
'deleted_at' => NilClass, # String (if deleted) OR NilClass
'account' => Brightbox::Compute::Formats::Nested::ACCOUNT,
'server_type' => Brightbox::Compute::Formats::Nested::SERVER_TYPE,
'cloud_ips' => [],
'image' => Brightbox::Compute::Formats::Nested::IMAGE,
'snapshots' => [],
'interfaces' => [Brightbox::Compute::Formats::Nested::INTERFACE],
'zone' => Brightbox::Compute::Formats::Nested::ZONE
}
end
module Collection
SERVERS = [Brightbox::Compute::Formats::Collected::SERVER]
end
end
end
end

View file

@ -1,6 +1,6 @@
Shindo.tests('Brightbox::Compute | server model', ['brightbox']) do
# image img-t4p09 = Ubuntu Maverick 10.10 server
server_tests(Brightbox[:compute], {:image_id => 'img-t4p09'}, false)
# image img-9vxqi = Ubuntu Maverick 10.10 server
server_tests(Brightbox[:compute], {:image_id => 'img-9vxqi'}, false)
end

View file

@ -0,0 +1,58 @@
Shindo.tests('Brightbox::Compute | server requests', ['brightbox']) do
tests('success') do
image_id = "img-9vxqi"
server_id = nil
tests("#create_server(:image => '#{image_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
data = Brightbox[:compute].create_server(:image => image_id)
server_id = data["id"]
data
end
Brightbox[:compute].servers.get(server_id).wait_for { ready? }
# Collection of Servers fails to match since deleted_at can be a String OR a NilClass
# tests("#list_servers()").formats(Brightbox::Compute::Formats::Collection::SERVERS) do
# Brightbox[:compute].list_servers()
# end
tests("#get_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
Brightbox[:compute].get_server(server_id)
end
tests("#update_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
Brightbox[:compute].update_server(server_id, :name => "New name from Fog test")
end
tests("#stop_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
Brightbox[:compute].stop_server(server_id)
end
tests("#start_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
Brightbox[:compute].start_server(server_id)
end
tests("#shutdown_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
Brightbox[:compute].shutdown_server(server_id)
end
tests("#destroy_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
Brightbox[:compute].destroy_server(server_id)
end
end
tests('failure') do
tests("#get_server('srv-00000')").raises(Excon::Errors::NotFound) do
Brightbox[:compute].get_server('srv-00000')
end
tests("#get_server()").raises(ArgumentError) do
Brightbox[:compute].get_server()
end
end
end