mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|databases] Finish request tests.
This commit is contained in:
parent
546a4e1db9
commit
490f4c6504
8 changed files with 259 additions and 54 deletions
|
@ -3,6 +3,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace'))
|
|||
module Fog
|
||||
module Rackspace
|
||||
class Databases < Fog::Service
|
||||
|
||||
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
||||
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
|
||||
class BadRequest < Fog::Rackspace::Errors::BadRequest; end
|
||||
|
||||
DFW_ENDPOINT = 'https://dfw.databases.api.rackspacecloud.com/v1.0/'
|
||||
LON_ENDPOINT = 'https://lon.databases.api.rackspacecloud.com/v1.0/'
|
||||
ORD_ENDPOINT = 'https://ord.databases.api.rackspacecloud.com/v1.0/'
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
Shindo.tests('Fog::Rackspace::Database | instance_tests', ['rackspace']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
@service = Fog::Rackspace::Databases.new
|
||||
|
||||
tests('success') do
|
||||
tests("#list_flavors_details").formats(DATABASE_FLAVORS_FORMAT) do
|
||||
@service.list_flavors_details.body
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
|
||||
LINK_FORMAT = [{'href' => String, 'rel' => String}]
|
||||
|
||||
DATABASE_INSTANCE_FORMAT = {
|
||||
'created' => String,
|
||||
'flavor' => {
|
||||
'id' => String,
|
||||
'links' => LINK_FORMAT
|
||||
},
|
||||
'hostname' => String,
|
||||
'id' => String,
|
||||
'links' => LINK_FORMAT,
|
||||
'name' => String,
|
||||
'status' => String,
|
||||
'updated' => String,
|
||||
'volume' => { 'size' => Integer},
|
||||
}
|
||||
DATABASE_CREATE_INSTANCE_FORMAT = {
|
||||
'instance' => DATABASE_INSTANCE_FORMAT
|
||||
}
|
||||
|
||||
DATABASE_GET_INSTANCE_FORMAT = {
|
||||
'instance' => DATABASE_INSTANCE_FORMAT.merge({'rootEnabled' => Fog::Boolean, 'volume' => {'size' => Integer, 'used' => Float}})
|
||||
}
|
||||
|
||||
DATABASE_LIST_INSTANCES_FORMAT = {
|
||||
'instances' => [
|
||||
DATABASE_INSTANCE_FORMAT
|
||||
]
|
||||
}
|
||||
|
||||
DATABASE_FLAVORS_FORMAT = {
|
||||
'flavors' => [
|
||||
{
|
||||
'id' => Integer,
|
||||
'vcpus' => Integer,
|
||||
'ram' => Integer,
|
||||
'links' => LINK_FORMAT,
|
||||
'name' => String
|
||||
}
|
||||
]
|
||||
}
|
36
tests/rackspace/requests/databases/database_tests.rb
Normal file
36
tests/rackspace/requests/databases/database_tests.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
Shindo.tests('Fog::Rackspace::Database | database_tests', ['rackspace']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
service = Fog::Rackspace::Databases.new
|
||||
instance_name = 'fog' + Time.now.to_i.to_s
|
||||
instance_id = service.create_instance(instance_name, 1, 1).body['instance']['id']
|
||||
|
||||
until service.get_instance(instance_id).body["instance"]["status"] == 'ACTIVE'
|
||||
sleep 10
|
||||
end
|
||||
|
||||
tests('success') do
|
||||
database_name = 'fogdb' + Time.now.to_i.to_s
|
||||
|
||||
tests("#create_database(#{instance_id}, #{database_name})").succeeds do
|
||||
service.create_database(instance_id, database_name).body
|
||||
end
|
||||
|
||||
tests("#list_databases{#{instance_id})").formats(LIST_DATABASES_FORMAT) do
|
||||
service.list_databases(instance_id).body
|
||||
end
|
||||
|
||||
tests("#delete_database(#{instance_id}, #{database_name})").succeeds do
|
||||
service.delete_database(instance_id, database_name)
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests("#create_database(#{instance_id}, '') => Invalid Create Critera").raises(Fog::Rackspace::Databases::BadRequest) do
|
||||
service.create_database(instance_id, '')
|
||||
end
|
||||
end
|
||||
|
||||
service.delete_instance(instance_id)
|
||||
end
|
16
tests/rackspace/requests/databases/flavor_tests.rb
Normal file
16
tests/rackspace/requests/databases/flavor_tests.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
Shindo.tests('Fog::Rackspace::Database | flavor_tests', ['rackspace']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
service = Fog::Rackspace::Databases.new
|
||||
|
||||
tests('success') do
|
||||
tests('#list_flavors_details').formats(LIST_FLAVORS_FORMAT) do
|
||||
service.list_flavors().body
|
||||
end
|
||||
|
||||
tests('#get_flavor(1)').formats(GET_FLAVOR_FORMAT) do
|
||||
service.get_flavor(1).body
|
||||
end
|
||||
end
|
||||
end
|
88
tests/rackspace/requests/databases/helper.rb
Normal file
88
tests/rackspace/requests/databases/helper.rb
Normal file
|
@ -0,0 +1,88 @@
|
|||
LINKS_FORMAT = [{
|
||||
'href' => String,
|
||||
'rel' => String
|
||||
}]
|
||||
|
||||
GET_FLAVOR_FORMAT = {
|
||||
'flavor' => {
|
||||
'id' => Integer,
|
||||
'name' => String,
|
||||
'ram' => Integer,
|
||||
'vcpus' => Integer,
|
||||
'links' => LINKS_FORMAT
|
||||
}
|
||||
}
|
||||
|
||||
LIST_FLAVORS_FORMAT = {
|
||||
'flavors' => [
|
||||
'id' => Integer,
|
||||
'name' => String,
|
||||
'links' => LINKS_FORMAT
|
||||
]
|
||||
}
|
||||
|
||||
INSTANCE_FORMAT = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'status' => String,
|
||||
'links' => LINKS_FORMAT,
|
||||
}
|
||||
|
||||
INSTANCE_DETAILS_FORMAT = INSTANCE_FORMAT.merge({
|
||||
'created' => String,
|
||||
'updated' => String,
|
||||
'hostname' => String,
|
||||
'flavor' => {
|
||||
'id' => String,
|
||||
'links' => LINKS_FORMAT
|
||||
},
|
||||
'volume' => {
|
||||
'size' => Integer
|
||||
}
|
||||
})
|
||||
|
||||
CREATE_INSTANCE_FORMAT = {
|
||||
'instance' => INSTANCE_DETAILS_FORMAT
|
||||
}
|
||||
|
||||
GET_INSTANCE_FORMAT = {
|
||||
'instance' => INSTANCE_DETAILS_FORMAT.merge({
|
||||
'rootEnabled' => Fog::Boolean,
|
||||
'volume' => {
|
||||
'size' => Integer,
|
||||
'used' => Float
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
LIST_INSTANCES_FORMAT = {
|
||||
'instances' => [
|
||||
INSTANCE_FORMAT
|
||||
]
|
||||
}
|
||||
|
||||
CHECK_ROOT_USER_FORMAT = {
|
||||
'rootEnabled' => Fog::Boolean
|
||||
}
|
||||
|
||||
ENABLE_ROOT_USER_FORMAT = {
|
||||
'user' => {
|
||||
'name' => String,
|
||||
'password' => String
|
||||
}
|
||||
}
|
||||
|
||||
LIST_DATABASES_FORMAT = {
|
||||
'databases' => [{
|
||||
'name' => String
|
||||
}]
|
||||
}
|
||||
|
||||
LIST_USERS_FORMAT = {
|
||||
'users' => [{
|
||||
'name' => String,
|
||||
'databases' => [{
|
||||
'name' => String
|
||||
}]
|
||||
}]
|
||||
}
|
77
tests/rackspace/requests/databases/instance_tests.rb
Normal file
77
tests/rackspace/requests/databases/instance_tests.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
Shindo.tests('Fog::Rackspace::Database | instance_tests', ['rackspace']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
service = Fog::Rackspace::Databases.new
|
||||
|
||||
tests('success') do
|
||||
|
||||
instance_id = nil
|
||||
instance_name = 'fog' + Time.now.to_i.to_s
|
||||
|
||||
tests("#list_instances").formats(LIST_INSTANCES_FORMAT) do
|
||||
service.list_instances.body
|
||||
end
|
||||
|
||||
tests("#create_instance(#{instance_name}, 1, 1)").formats(CREATE_INSTANCE_FORMAT) do
|
||||
data = service.create_instance(instance_name, 1, 1).body
|
||||
instance_id = data['instance']['id']
|
||||
data
|
||||
end
|
||||
|
||||
until service.get_instance(instance_id).body["instance"]["status"] == 'ACTIVE'
|
||||
sleep 10
|
||||
end
|
||||
|
||||
tests("#get_instance(#{instance_id})").formats(GET_INSTANCE_FORMAT) do
|
||||
service.get_instance(instance_id).body
|
||||
end
|
||||
|
||||
tests("#check_root_user(#{instance_id})").formats(CHECK_ROOT_USER_FORMAT) do
|
||||
service.check_root_user(instance_id).body
|
||||
end
|
||||
|
||||
tests("#enable_root_user(#{instance_id})").formats(ENABLE_ROOT_USER_FORMAT) do
|
||||
service.enable_root_user(instance_id).body
|
||||
end
|
||||
|
||||
tests("#restart_instance(#{instance_id})").succeeds do
|
||||
service.restart_instance(instance_id)
|
||||
end
|
||||
|
||||
until service.get_instance(instance_id).body["instance"]["status"] == 'ACTIVE'
|
||||
sleep 10
|
||||
end
|
||||
|
||||
tests("#resize_instance(#{instance_id}, 2)").succeeds do
|
||||
service.resize_instance(instance_id, 2)
|
||||
end
|
||||
|
||||
until service.get_instance(instance_id).body["instance"]["status"] == 'ACTIVE'
|
||||
sleep 10
|
||||
end
|
||||
|
||||
tests("#resize_instance_volume(#{instance_id}, 2)").succeeds do
|
||||
service.resize_instance_volume(instance_id, 2)
|
||||
end
|
||||
|
||||
until service.get_instance(instance_id).body["instance"]["status"] == 'ACTIVE'
|
||||
sleep 10
|
||||
end
|
||||
|
||||
tests("#delete_instance(#{instance_id})").succeeds do
|
||||
service.delete_instance(instance_id)
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests("#create_instance('', 0, 0) => Invalid Create Critera").raises(Fog::Rackspace::Databases::BadRequest) do
|
||||
service.create_instance('', 0, 0)
|
||||
end
|
||||
|
||||
tests("#get_instance('') => Does not exist").raises(Fog::Rackspace::Databases::NotFound) do
|
||||
service.get_instance('')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
37
tests/rackspace/requests/databases/user_tests.rb
Normal file
37
tests/rackspace/requests/databases/user_tests.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
Shindo.tests('Fog::Rackspace::Database | user_tests', ['rackspace']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
service = Fog::Rackspace::Databases.new
|
||||
instance_name = 'fog' + Time.now.to_i.to_s
|
||||
instance_id = service.create_instance(instance_name, 1, 1).body['instance']['id']
|
||||
|
||||
until service.get_instance(instance_id).body["instance"]["status"] == 'ACTIVE'
|
||||
sleep 10
|
||||
end
|
||||
|
||||
tests('success') do
|
||||
user_name = 'fog' + Time.now.to_i.to_s
|
||||
password = 'password1'
|
||||
|
||||
tests("#create_user(#{instance_id}, #{user_name}, #{password})").succeeds do
|
||||
service.create_user(instance_id, user_name, password).body
|
||||
end
|
||||
|
||||
tests("#list_users{#{instance_id})").formats(LIST_USERS_FORMAT) do
|
||||
service.list_users(instance_id).body
|
||||
end
|
||||
|
||||
tests("#delete_user(#{instance_id}, #{user_name})").succeeds do
|
||||
service.delete_user(instance_id, user_name)
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests("#create_user(#{instance_id}, '', '') => Invalid Create Critera").raises(Fog::Rackspace::Databases::BadRequest) do
|
||||
service.create_user(instance_id, '', '')
|
||||
end
|
||||
end
|
||||
|
||||
service.delete_instance(instance_id)
|
||||
end
|
Loading…
Reference in a new issue