mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|databases] Add model tests.
This commit is contained in:
parent
bd5789e23f
commit
b0310a6a97
8 changed files with 168 additions and 0 deletions
|
@ -4,6 +4,14 @@ module Fog
|
||||||
module Rackspace
|
module Rackspace
|
||||||
class Databases
|
class Databases
|
||||||
class Instance < Fog::Model
|
class Instance < Fog::Model
|
||||||
|
# States
|
||||||
|
ACTIVE = 'ACTIVE'
|
||||||
|
BUILD = 'BUILD'
|
||||||
|
BLOCKED = 'BLOCKED'
|
||||||
|
REBOOT = 'REBOOT'
|
||||||
|
RESIZE = 'RESIZE'
|
||||||
|
SHUTDOWN = 'SHUTDOWN'
|
||||||
|
|
||||||
identity :id
|
identity :id
|
||||||
|
|
||||||
attribute :name
|
attribute :name
|
||||||
|
@ -53,6 +61,10 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ready?
|
||||||
|
state == ACTIVE
|
||||||
|
end
|
||||||
|
|
||||||
def root_user_enabled?
|
def root_user_enabled?
|
||||||
requires :identity
|
requires :identity
|
||||||
connection.check_root_user(identity).body['rootEnabled']
|
connection.check_root_user(identity).body['rootEnabled']
|
||||||
|
@ -69,18 +81,21 @@ module Fog
|
||||||
def restart
|
def restart
|
||||||
requires :identity
|
requires :identity
|
||||||
connection.restart_instance(identity)
|
connection.restart_instance(identity)
|
||||||
|
self.state = REBOOT
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def resize(flavor_id)
|
def resize(flavor_id)
|
||||||
requires :identity
|
requires :identity
|
||||||
connection.resize_instance(identity, flavor_id)
|
connection.resize_instance(identity, flavor_id)
|
||||||
|
self.state = RESIZE
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def resize_volume(volume_size)
|
def resize_volume(volume_size)
|
||||||
requires :identity
|
requires :identity
|
||||||
connection.resize_instance_volume(identity, volume_size)
|
connection.resize_instance_volume(identity, volume_size)
|
||||||
|
self.state = RESIZE
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
17
tests/rackspace/models/databases/database_tests.rb
Normal file
17
tests/rackspace/models/databases/database_tests.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Databases | database', ['rackspace']) do
|
||||||
|
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
service = Fog::Rackspace::Databases.new
|
||||||
|
instance = service.instances.create({
|
||||||
|
:name => "fog_instance_#{Time.now.to_i.to_s}",
|
||||||
|
:flavor_id => 1,
|
||||||
|
:volume_size => 1
|
||||||
|
})
|
||||||
|
|
||||||
|
instance.wait_for { ready? }
|
||||||
|
|
||||||
|
model_tests(instance.databases, { :name => "db_#{Time.now.to_i.to_s}" }, false)
|
||||||
|
|
||||||
|
instance.destroy
|
||||||
|
end
|
17
tests/rackspace/models/databases/databases_tests.rb
Normal file
17
tests/rackspace/models/databases/databases_tests.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Databases | databases', ['rackspace']) do
|
||||||
|
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
service = Fog::Rackspace::Databases.new
|
||||||
|
instance = service.instances.create({
|
||||||
|
:name => "fog_instance_#{Time.now.to_i.to_s}",
|
||||||
|
:flavor_id => 1,
|
||||||
|
:volume_size => 1
|
||||||
|
})
|
||||||
|
|
||||||
|
instance.wait_for { ready? }
|
||||||
|
|
||||||
|
collection_tests(instance.databases, { :name => "db_#{Time.now.to_i.to_s}" }, false)
|
||||||
|
|
||||||
|
instance.destroy
|
||||||
|
end
|
20
tests/rackspace/models/databases/flavors_tests.rb
Normal file
20
tests/rackspace/models/databases/flavors_tests.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Databases | flavors', ['rackspace']) do
|
||||||
|
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
service = Fog::Rackspace::Databases.new
|
||||||
|
|
||||||
|
tests("success") do
|
||||||
|
tests("#all").succeeds do
|
||||||
|
service.flavors.all
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#get").succeeds do
|
||||||
|
service.flavors.get(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("failure").returns(nil) do
|
||||||
|
service.flavors.get('some_random_identity')
|
||||||
|
end
|
||||||
|
end
|
43
tests/rackspace/models/databases/instance_tests.rb
Normal file
43
tests/rackspace/models/databases/instance_tests.rb
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Databases | instance', ['rackspace']) do
|
||||||
|
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
service = Fog::Rackspace::Databases.new
|
||||||
|
options = {
|
||||||
|
:name => "fog_instance_#{Time.now.to_i.to_s}",
|
||||||
|
:flavor_id => 1,
|
||||||
|
:volume_size => 1
|
||||||
|
}
|
||||||
|
|
||||||
|
model_tests(service.instances, options, false) do
|
||||||
|
@instance.wait_for { ready? }
|
||||||
|
tests('root_user_enabled before user is enabled').returns(false) do
|
||||||
|
@instance.root_user_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.wait_for { ready? }
|
||||||
|
tests('enable_root_user sets root user and password').succeeds do
|
||||||
|
@instance.enable_root_user
|
||||||
|
returns(false) { @instance.root_user.nil? }
|
||||||
|
returns(false) { @instance.root_password.nil? }
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.wait_for { ready? }
|
||||||
|
tests('restarts instance').succeeds do
|
||||||
|
@instance.restart
|
||||||
|
returns('REBOOT') { @instance.state }
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.wait_for { ready? }
|
||||||
|
tests('resizes instance').succeeds do
|
||||||
|
@instance.resize(2)
|
||||||
|
returns('RESIZE') { @instance.state }
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.wait_for { ready? }
|
||||||
|
tests('restarts instance').succeeds do
|
||||||
|
@instance.resize_volume(2)
|
||||||
|
returns('RESIZE') { @instance.state }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
14
tests/rackspace/models/databases/instances_tests.rb
Normal file
14
tests/rackspace/models/databases/instances_tests.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Databases | instances', ['rackspace']) do
|
||||||
|
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
service = Fog::Rackspace::Databases.new
|
||||||
|
options = {
|
||||||
|
:name => "fog_instance_#{Time.now.to_i.to_s}",
|
||||||
|
:flavor_id => 1,
|
||||||
|
:volume_size => 1
|
||||||
|
}
|
||||||
|
collection_tests(service.instances, options, false) do
|
||||||
|
@instance.wait_for { ready? }
|
||||||
|
end
|
||||||
|
end
|
21
tests/rackspace/models/databases/user_tests.rb
Normal file
21
tests/rackspace/models/databases/user_tests.rb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Databases | user', ['rackspace']) do
|
||||||
|
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
service = Fog::Rackspace::Databases.new
|
||||||
|
instance = service.instances.create({
|
||||||
|
:name => "fog_instance_#{Time.now.to_i.to_s}",
|
||||||
|
:flavor_id => 1,
|
||||||
|
:volume_size => 1
|
||||||
|
})
|
||||||
|
|
||||||
|
instance.wait_for { ready? }
|
||||||
|
|
||||||
|
options = {
|
||||||
|
:name => "user_#{Time.now.to_i.to_s}",
|
||||||
|
:password => "fog_user"
|
||||||
|
}
|
||||||
|
model_tests(instance.users, options, false)
|
||||||
|
|
||||||
|
instance.destroy
|
||||||
|
end
|
21
tests/rackspace/models/databases/users_tests.rb
Normal file
21
tests/rackspace/models/databases/users_tests.rb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Databases | users', ['rackspace']) do
|
||||||
|
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
service = Fog::Rackspace::Databases.new
|
||||||
|
instance = service.instances.create({
|
||||||
|
:name => "fog_instance_#{Time.now.to_i.to_s}",
|
||||||
|
:flavor_id => 1,
|
||||||
|
:volume_size => 1
|
||||||
|
})
|
||||||
|
|
||||||
|
instance.wait_for { ready? }
|
||||||
|
|
||||||
|
options = {
|
||||||
|
:name => "user_#{Time.now.to_i.to_s}",
|
||||||
|
:password => "fog_user"
|
||||||
|
}
|
||||||
|
collection_tests(instance.users, options, false)
|
||||||
|
|
||||||
|
instance.destroy
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue