mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[clodo|compute] Add tests.
This commit is contained in:
parent
f1ef97f59f
commit
adabe65aba
2 changed files with 138 additions and 6 deletions
36
tests/clodo/requests/compute/image_tests.rb
Normal file
36
tests/clodo/requests/compute/image_tests.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
Shindo.tests('Fog::Compute[:clodo] | image requests', ['clodo']) do
|
||||
|
||||
### Fog.mock!
|
||||
|
||||
clodo = Fog::Compute[:clodo]
|
||||
|
||||
@image_format = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'status' => String,
|
||||
'vps_type' => String
|
||||
}
|
||||
|
||||
@image_details_format = {
|
||||
'os_type' => String,
|
||||
'os_bits' => String,
|
||||
'os_hvm' => String,
|
||||
'_attr' => @image_format
|
||||
}
|
||||
|
||||
tests("success") do
|
||||
tests("- list_images").formats([@image_format]) do
|
||||
clodo.list_images.body['images']
|
||||
end
|
||||
|
||||
tests("- list_images_detail").formats([@image_details_format]) do
|
||||
clodo.list_images_detail.body['images']
|
||||
end
|
||||
end
|
||||
|
||||
tests("failure") do
|
||||
tests("- get_image_details(541)").returns(nil) do
|
||||
clodo.images.get(541)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,15 +1,54 @@
|
|||
Shindo.tests('Fog::Compute[:clodo] | server requests', ['clodo']) do
|
||||
|
||||
@ip_format = {
|
||||
'ddosprotect' => Fog::Boolean,
|
||||
'primary_ip' => Fog::Boolean,
|
||||
'isp' => Fog::Boolean,
|
||||
'ip' => String
|
||||
}
|
||||
|
||||
@server_format = {
|
||||
'addresses' => {
|
||||
'public' => [String]
|
||||
'public' => [@ip_format]
|
||||
},
|
||||
'id' => Integer,
|
||||
'imageId' => Integer,
|
||||
'id' => String,
|
||||
'imageId' => String,
|
||||
'name' => String,
|
||||
'type' => String,
|
||||
'status' => String
|
||||
}
|
||||
|
||||
@server_details_format = @server_format.merge({
|
||||
'id' => Integer,
|
||||
'vps_createdate' => String,
|
||||
'vps_hdd_max' => String,
|
||||
'vps_traff' => NilClass,
|
||||
'vps_mem_1h_max' => String,
|
||||
'vps_mem_load' => String,
|
||||
'vps_user_pass' => String,
|
||||
'vps_vnc_pass' => String,
|
||||
'vps_adddate' => String,
|
||||
'vps_os_title' => String,
|
||||
'vps_update' => String,
|
||||
'vps_mem_1h_min' => String,
|
||||
'vps_mem_1h_avg' => NilClass,
|
||||
'vps_memory_max' => String,
|
||||
'vps_os_version' => String,
|
||||
'vps_cpu_1h_max' => String,
|
||||
'vps_hdd_load' => String,
|
||||
'vps_disk_load' => String,
|
||||
'vps_os_type' => String,
|
||||
'vps_memory' => String,
|
||||
'vps_cpu_load' => String,
|
||||
'vps_update_days' => String,
|
||||
'vps_os_bits' => String,
|
||||
'vps_vnc' => String,
|
||||
'vps_cpu_max' => String,
|
||||
'vps_cpu_1h_min' => String,
|
||||
'vps_cpu_1h_avg' => NilClass,
|
||||
'vps_root_pass' => String
|
||||
})
|
||||
|
||||
@server_create_format = {
|
||||
'name' => String,
|
||||
'adminPass' => String,
|
||||
|
@ -17,22 +56,79 @@ Shindo.tests('Fog::Compute[:clodo] | server requests', ['clodo']) do
|
|||
'id' => Integer
|
||||
}
|
||||
|
||||
# Fog.mock!
|
||||
|
||||
@clodo = Fog::Compute::Clodo.new
|
||||
clodo = Fog::Compute[:clodo]
|
||||
|
||||
tests('success') do
|
||||
tests('- create_server(541)').formats(@server_create_format) do
|
||||
data = @clodo.create_server(541,{:vps_type => 'ScaleServer'}).body['server']
|
||||
data = clodo.create_server(541,{:vps_type => 'ScaleServer'}).body['server']
|
||||
@server_id = data['id']
|
||||
data
|
||||
end
|
||||
|
||||
tests('- list_servers(ready)').formats([@server_format]) do
|
||||
clodo.list_servers.body['servers'].reject {|s| !['is_running', 'is_disabled'].include?(s['status']) }
|
||||
end
|
||||
|
||||
tests('- list_servers(not ready)').formats([@server_format.merge({'addresses'=>{'public'=>NilClass}})]) do
|
||||
clodo.list_servers.body['servers'].reject {|s| !['is_request'].include?(s['status']) }
|
||||
end
|
||||
|
||||
clodo.servers.get(@server_id).wait_for { ready? || state == 'is_error' } unless Fog.mocking?
|
||||
|
||||
tests("- get_server_details(#{@server_id})").formats(@server_details_format) do
|
||||
clodo.get_server_details(@server_id).body['server']
|
||||
end
|
||||
|
||||
tests("- reboot_server(#{@server_id})").succeeds do
|
||||
clodo.reboot_server(@server_id, :hard)
|
||||
end
|
||||
|
||||
clodo.servers.get(@server_id).wait_for { ready? || state == 'is_error' } unless Fog.mocking?
|
||||
|
||||
tests("- stop_server(#{@server_id})").succeeds do
|
||||
clodo.stop_server(@server_id)
|
||||
end
|
||||
|
||||
unless Fog.mocking?
|
||||
clodo.servers.get(@server_id).wait_for { state == 'is_disabled' || state == 'is_disabled' }
|
||||
end
|
||||
|
||||
tests("- start_server(#{@server_id})").succeeds do
|
||||
clodo.start_server(@server_id)
|
||||
end
|
||||
|
||||
clodo.servers.get(@server_id).wait_for { ready? || state == 'is_error' } unless Fog.mocking?
|
||||
|
||||
tests("- delete_server(#{@server_id})").succeeds do
|
||||
clodo.delete_server(@server_id)
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('- create_server(0)').raises(Excon::Errors::BadRequest) do
|
||||
data = @clodo.create_server(0,{:vps_type => 'ScaleServer'}).body['server']
|
||||
data = clodo.create_server(0,{:vps_type => 'ScaleServer'}).body['server']
|
||||
@server_id = data['id']
|
||||
data
|
||||
end
|
||||
|
||||
tests("- reboot_server(0)").raises(Excon::Errors::BadRequest) do
|
||||
clodo.reboot_server(0, :hard)
|
||||
end
|
||||
|
||||
tests("- stop_server(0)").raises(Excon::Errors::BadRequest) do
|
||||
clodo.stop_server(0)
|
||||
end
|
||||
|
||||
tests("- start_server(0)").raises(Excon::Errors::BadRequest) do
|
||||
clodo.start_server(0)
|
||||
end
|
||||
|
||||
## delete_server(0) in actial API, works not as it must,
|
||||
## so I do not include this test in tests sequence.
|
||||
# tests("- delete_server(0)").raises(Fog::Compute::Clodo::NotFound) do
|
||||
# clodo.delete_server(0)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue