[brightbox] Tests for remaining API requests

* Request tests for accounts, api_clients, cloud_ips, images, interfaces, server types, user and zones
* Added 'ready?' methods to CloudIp and Image models
* Reworked brightbox helper to include Format patterns for all of the
* Added "hack" to allow select objects to be one class OR NilClass for fields that may be a JSON string or null if unset
* Some tests are not enabled (commented out) because they need manual steps (such as uploading Image to your account before registration)
This commit is contained in:
Paul Thornthwaite 2010-12-06 14:50:59 +00:00
parent a327b3446c
commit 6500fa46bf
12 changed files with 612 additions and 63 deletions

View File

@ -26,6 +26,10 @@ module Fog
connection.map_cloud_ip(identity, :interface => interface_to_map)
end
def mapped?
status == "mapped"
end
def unmap
requires :identity
connection.unmap_cloud_ip(identity)

View File

@ -26,6 +26,10 @@ module Fog
attribute :disk_size
attribute :created_at
def ready?
status == "available"
end
def save
requires :source, :arch
options = {

View File

@ -1,3 +1,34 @@
module Fog
module Brightbox
module Nullable
module String; end
module Account; end
module Image; end
module Interface; end
module Server; end
module Zone; end
end
end
end
String.send :include, Fog::Brightbox::Nullable::String
NilClass.send :include, Fog::Brightbox::Nullable::String
Hash.send :include, Fog::Brightbox::Nullable::Account
NilClass.send :include, Fog::Brightbox::Nullable::Account
Hash.send :include, Fog::Brightbox::Nullable::Image
NilClass.send :include, Fog::Brightbox::Nullable::Image
Hash.send :include, Fog::Brightbox::Nullable::Interface
NilClass.send :include, Fog::Brightbox::Nullable::Interface
Hash.send :include, Fog::Brightbox::Nullable::Server
NilClass.send :include, Fog::Brightbox::Nullable::Server
Hash.send :include, Fog::Brightbox::Nullable::Zone
NilClass.send :include, Fog::Brightbox::Nullable::Zone
class Brightbox
module Compute
module TestSupport
@ -6,27 +37,6 @@ class Brightbox
end
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,
@ -38,12 +48,21 @@ class Brightbox
"limits_cloudips" => Integer
}
INTERFACE = {
API_CLIENT = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"description" => String
}
CLOUD_IP = {
"id" => String,
"ipv4_address" => String,
"mac_address" => String
"resource_type" => String,
"url" => String,
"public_ip" => String,
"status" => String,
"reverse_dns" => String
}
IMAGE = {
@ -58,53 +77,292 @@ class Brightbox
"status" => String,
"owner" => String
}
end
module Full
INTERFACE = {
"resource_type" => String,
"url" => String,
"id" => String,
"ipv4_address" => String,
"mac_address" => String
}
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
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"status" => String,
"hostname" => String,
"created_at" => String,
"started_at" => Fog::Brightbox::Nullable::String,
"deleted_at" => Fog::Brightbox::Nullable::String
}
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
}
USER = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"email_address" => String
}
ZONE = {
"id" => String,
"resource_type" => String,
"url" => String,
"handle" => Fog::Brightbox::Nullable::String
}
end
module Collected
API_CLIENT = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"description" => String,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT
}
CLOUD_IP = {
"id" => String,
"resource_type" => String,
"url" => String,
"public_ip" => String,
"status" => String,
"reverse_dns" => String,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"interface" => Fog::Brightbox::Nullable::Interface,
"server" => NilClass
}
IMAGE = {
"name" => String,
"created_at" => String,
"resource_type" => String,
"arch" => String,
"url" => String,
"id" => String,
"description" => String,
"source" => String,
"source_type" => String,
"status" => String,
"owner" => String,
"public" => Fog::Boolean,
"official" => Fog::Boolean,
"compatibility_mode" => Fog::Boolean,
"virtual_size" => Integer,
"disk_size" => Integer,
"ancestor" => Fog::Brightbox::Nullable::Image
}
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
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"status" => String,
"hostname" => String,
"created_at" => String,
"started_at" => Fog::Brightbox::Nullable::String,
"deleted_at" => Fog::Brightbox::Nullable::String,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"server_type" => Brightbox::Compute::Formats::Nested::SERVER_TYPE,
"cloud_ips" => [Brightbox::Compute::Formats::Nested::CLOUD_IP],
"image" => Brightbox::Compute::Formats::Nested::IMAGE,
"snapshots" => [Brightbox::Compute::Formats::Nested::IMAGE],
"interfaces" => [Brightbox::Compute::Formats::Nested::INTERFACE],
"zone" => Fog::Brightbox::Nullable::Zone
}
SERVER_TYPE = {
"id" => String,
"resource_type" => String,
"url" => String,
"handle" => Fog::Brightbox::Nullable::String,
"name" => String,
"status" => String,
"cores" => Integer,
"ram" => Integer,
"disk_size" => Integer
}
USER = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"email_address" => String,
"email_verified" => Fog::Boolean,
"accounts" => [],
"default_account" => NilClass
}
ZONE = {
"id" => String,
"resource_type" => String,
"url" => String,
"handle" => Fog::Brightbox::Nullable::String
}
end
module Full
ACCOUNT = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"status" => String,
"address_1" => String,
"address_2" => String,
"city" => String,
"county" => String,
"postcode" => String,
"country_code" => String,
"country_name" => String,
"vat_registration_number" => Fog::Brightbox::Nullable::String,
"telephone_number" => String,
"telephone_verified" => Fog::Boolean,
"created_at" => String,
"ram_limit" => Integer,
"ram_used" => Integer,
"limits_cloudips" => Integer,
"library_ftp_host" => String,
"library_ftp_user" => String,
"library_ftp_password" => Fog::Brightbox::Nullable::String,
"owner" => Brightbox::Compute::Formats::Nested::USER,
"users" => [Brightbox::Compute::Formats::Nested::USER],
"clients" => [Brightbox::Compute::Formats::Nested::API_CLIENT],
"servers" => [Brightbox::Compute::Formats::Nested::SERVER],
"images" => [Brightbox::Compute::Formats::Nested::IMAGE],
"zones" => [Brightbox::Compute::Formats::Nested::ZONE]
}
API_CLIENT = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"description" => String,
"secret" => Fog::Brightbox::Nullable::String,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT
}
CLOUD_IP = {
"id" => String,
"resource_type" => String,
"url" => String,
"public_ip" => String,
"status" => String,
"reverse_dns" => String,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"interface" => Fog::Brightbox::Nullable::Interface,
"server" => Fog::Brightbox::Nullable::Server
}
IMAGE = {
"name" => String,
"created_at" => String,
"resource_type" => String,
"arch" => String,
"url" => String,
"id" => String,
"description" => String,
"source" => String,
"source_type" => String,
"status" => String,
"owner" => String, # Account ID not object
"public" => Fog::Boolean,
"official" => Fog::Boolean,
"compatibility_mode" => Fog::Boolean,
"virtual_size" => Integer,
"disk_size" => Integer,
"ancestor" => Fog::Brightbox::Nullable::Image
}
INTERFACE = {
"resource_type" => String,
"url" => String,
"id" => String,
"ipv4_address" => String,
"mac_address" => String,
"server" => Brightbox::Compute::Formats::Nested::SERVER
}
SERVER = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"status" => String,
"hostname" => String,
"created_at" => String,
"started_at" => Fog::Brightbox::Nullable::String,
"deleted_at" => Fog::Brightbox::Nullable::String,
"user_data" => Fog::Brightbox::Nullable::String,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"server_type" => Brightbox::Compute::Formats::Nested::SERVER_TYPE,
"cloud_ips" => [Brightbox::Compute::Formats::Nested::CLOUD_IP],
"image" => Brightbox::Compute::Formats::Nested::IMAGE,
"snapshots" => [Brightbox::Compute::Formats::Nested::IMAGE],
"interfaces" => [Brightbox::Compute::Formats::Nested::INTERFACE],
"zone" => Brightbox::Compute::Formats::Nested::ZONE
}
SERVER_TYPE = {
"id" => String,
"resource_type" => String,
"url" => String,
"handle" => Fog::Brightbox::Nullable::String,
"name" => String,
"status" => String,
"cores" => Integer,
"ram" => Integer,
"disk_size" => Integer
}
USER = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"email_address" => String,
"email_verified" => Fog::Boolean,
"accounts" => [Brightbox::Compute::Formats::Nested::ACCOUNT],
"default_account" => Fog::Brightbox::Nullable::Account,
"ssh_key" => Fog::Brightbox::Nullable::String
}
ZONE = {
"id" => String,
"resource_type" => String,
"url" => String,
"handle" => String
}
end
module Collection
API_CLIENTS = [Brightbox::Compute::Formats::Collected::API_CLIENT]
CLOUD_IPS = [Brightbox::Compute::Formats::Collected::CLOUD_IP]
IMAGES = [Brightbox::Compute::Formats::Collected::IMAGE]
SERVERS = [Brightbox::Compute::Formats::Collected::SERVER]
SERVER_TYPES = [Brightbox::Compute::Formats::Collected::SERVER_TYPE]
USERS = [Brightbox::Compute::Formats::Collected::USER]
ZONES = [Brightbox::Compute::Formats::Collected::ZONE]
end
end

View File

@ -0,0 +1,29 @@
Shindo.tests('Brightbox::Compute | account requests', ['brightbox']) do
tests('success') do
tests("#get_account()").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do
Brightbox[:compute].get_account()
end
original_name = Brightbox[:compute].get_account["name"]
update_args = {:name => "New name from Fog test"}
tests("#update_account(#{update_args.inspect})").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do
Brightbox[:compute].update_account(update_args)
end
Brightbox[:compute].update_account(:name => original_name)
tests("#reset_ftp_password_account()").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do
Brightbox[:compute].reset_ftp_password_account()
end
end
tests('failure') do
tests("#update_account()").returns(nil) do
Brightbox[:compute].update_account()
end
end
end

View File

@ -0,0 +1,41 @@
Shindo.tests('Brightbox::Compute | api client requests', ['brightbox']) do
tests('success') do
create_options = {:name => "Name from Fog test (#{Time.now.to_i})", :description => "Description from Fog test"}
tests("#create_api_client(#{create_options.inspect})").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
data = Brightbox[:compute].create_api_client(create_options)
@api_client_id = data["id"]
data
end
tests("#list_api_clients()").formats(Brightbox::Compute::Formats::Collection::API_CLIENTS) do
Brightbox[:compute].list_api_clients()
end
tests("#get_api_client('#{@api_client_id}')").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
Brightbox[:compute].get_api_client(@api_client_id)
end
tests("#update_api_client('#{@api_client_id}')").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
Brightbox[:compute].update_api_client(@api_client_id, :name => "New name from Fog test")
end
tests("#destroy_api_client('#{@api_client_id}')").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
Brightbox[:compute].destroy_api_client(@api_client_id)
end
end
tests('failure') do
tests("#get_api_client('cli-00000')").raises(Excon::Errors::NotFound) do
Brightbox[:compute].get_api_client('cli-00000')
end
tests("#get_api_client()").raises(ArgumentError) do
Brightbox[:compute].get_api_client()
end
end
end

View File

@ -0,0 +1,49 @@
Shindo.tests('Brightbox::Compute | cloud ip requests', ['brightbox']) do
tests('success') do
tests("#create_cloud_ip()").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
data = Brightbox[:compute].create_cloud_ip()
@cloud_ip_id = data["id"]
data
end
tests("#list_cloud_ips()").formats(Brightbox::Compute::Formats::Collection::CLOUD_IPS) do
Brightbox[:compute].list_cloud_ips()
end
tests("#get_cloud_ip('#{@cloud_ip_id}')").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
Brightbox[:compute].get_cloud_ip(@cloud_ip_id)
end
server = Brightbox[:compute].servers.first
interface_id = server.interfaces.first["id"]
map_options = {:interface => interface_id}
tests("#map_cloud_ip('#{@cloud_ip_id}', #{map_options.inspect})").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
Brightbox[:compute].map_cloud_ip(@cloud_ip_id, map_options)
end
Brightbox[:compute].cloud_ips.get(@cloud_ip_id).wait_for { mapped? }
tests("#unmap_cloud_ip('#{@cloud_ip_id}')").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
Brightbox[:compute].unmap_cloud_ip(@cloud_ip_id)
end
tests("#destroy_cloud_ip('#{@cloud_ip_id}')").formats(Brightbox::Compute::Formats::Full::CLOUD_IP) do
Brightbox[:compute].destroy_cloud_ip(@cloud_ip_id)
end
end
tests('failure') do
tests("#get_cloud_ip('cip-00000')").raises(Excon::Errors::NotFound) do
Brightbox[:compute].get_cloud_ip('cip-00000')
end
tests("#get_cloud_ip()").raises(ArgumentError) do
Brightbox[:compute].get_cloud_ip()
end
end
end

View File

@ -0,0 +1,52 @@
Shindo.tests('Brightbox::Compute | image requests', ['brightbox']) do
tests('success') do
## Difficult to test without having uploaded an Image to your account to register
# creation_options = {
# "arch" => "i686",
# "source" => "fnord"
# }
# tests("#create_image(#{creation_options.inspect})").formats(Brightbox::Compute::Formats::Full::IMAGE) do
# data = Brightbox[:compute].create_image(creation_options)
# @image_id = data["id"]
# data
# end
# Brightbox[:compute].images.get(@image_id).wait_for { ready? }
tests("#list_images()").formats(Brightbox::Compute::Formats::Collection::IMAGES) do
data = Brightbox[:compute].list_images()
@image_id = data.first["id"]
data
end
tests("#get_image('#{@image_id}')").formats(Brightbox::Compute::Formats::Full::IMAGE) do
Brightbox[:compute].get_image(@image_id)
end
## Until Image creation can be automated, we shouldn't be updating Images randomly
# update_options = {}
# tests("#update_image('#{@image_id}', #{update_options.inspect})").formats(Brightbox::Compute::Formats::Full::IMAGE) do
# Brightbox[:compute].update_image(@image_id, :name => "New name from Fog test")
# end
## Same as other tests - can't be deleting them unless part of the test run
# tests("#destroy_server('#{@image_id}')").formats(Brightbox::Compute::Formats::Full::IMAGE) do
# Brightbox[:compute].destroy_image(@image_id)
# end
end
tests('failure') do
tests("#get_image('img-00000')").raises(Excon::Errors::NotFound) do
Brightbox[:compute].get_image('img-00000')
end
tests("#get_image()").raises(ArgumentError) do
Brightbox[:compute].get_image()
end
end
end

View File

@ -0,0 +1,24 @@
Shindo.tests('Brightbox::Compute | interface requests', ['brightbox']) do
tests('success') do
server = Brightbox[:compute].servers.first
@interface_id = server.interfaces.first["id"]
tests("#get_interface('#{@interface_id}')").formats(Brightbox::Compute::Formats::Full::INTERFACE) do
Brightbox[:compute].get_interface(@interface_id)
end
end
tests('failure') do
tests("#get_interface('int-00000')").raises(Excon::Errors::Forbidden) do
Brightbox[:compute].get_interface('int-00000')
end
tests("#get_interface()").raises(ArgumentError) do
Brightbox[:compute].get_interface()
end
end
end

View File

@ -13,10 +13,9 @@ Shindo.tests('Brightbox::Compute | server requests', ['brightbox']) do
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("#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)

View File

@ -0,0 +1,28 @@
Shindo.tests('Brightbox::Compute | server type requests', ['brightbox']) do
tests('success') do
tests("#list_server_types()").formats(Brightbox::Compute::Formats::Collection::SERVER_TYPES) do
data = Brightbox[:compute].list_server_types()
@server_type_id = data.first["id"]
data
end
tests("#get_server_type('#{@server_type_id}')").formats(Brightbox::Compute::Formats::Full::SERVER_TYPE) do
Brightbox[:compute].get_server_type(@server_type_id)
end
end
tests('failure') do
tests("#get_server_type('typ-00000')").raises(Excon::Errors::NotFound) do
Brightbox[:compute].get_server_type('typ-00000')
end
tests("#get_server()").raises(ArgumentError) do
Brightbox[:compute].get_server_type()
end
end
end

View File

@ -0,0 +1,33 @@
Shindo.tests('Brightbox::Compute | user requests', ['brightbox']) do
tests('success') do
tests("#list_users()").formats(Brightbox::Compute::Formats::Collection::USERS) do
data = Brightbox[:compute].list_users()
@user_id = data.first["id"]
data
end
tests("#get_user('#{@user_id}')").formats(Brightbox::Compute::Formats::Full::USER) do
data = Brightbox[:compute].get_user(@user_id)
@original_name = data["name"]
data
end
update_options = { :name => "New name from Fog" }
tests("#update_user('#{@user_id}', #{update_options.inspect})").formats(Brightbox::Compute::Formats::Full::USER) do
Brightbox[:compute].update_user(@user_id, update_options)
end
Brightbox[:compute].update_user(@user_id, :name => @original_name)
end
tests('failure') do
tests("#update_user()").raises(ArgumentError) do
Brightbox[:compute].update_user()
end
end
end

View File

@ -0,0 +1,28 @@
Shindo.tests('Brightbox::Compute | zone requests', ['brightbox']) do
tests('success') do
tests("#list_zones()").formats(Brightbox::Compute::Formats::Collection::ZONES) do
data = Brightbox[:compute].list_zones()
@zone_id = data.first["id"]
data
end
tests("#get_zone('#{@zone_id}')").formats(Brightbox::Compute::Formats::Full::ZONE) do
Brightbox[:compute].get_zone(@zone_id)
end
end
tests('failure') do
tests("#get_zone('zon-00000')").raises(Excon::Errors::NotFound) do
Brightbox[:compute].get_zone('zon-00000')
end
tests("#get_zone()").raises(ArgumentError) do
Brightbox[:compute].get_zone()
end
end
end