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

[rackspace] progress toward converting specs to shindo

This commit is contained in:
geemus (Wesley Beary) 2010-04-06 21:47:13 -07:00
parent 4421d86953
commit ace2752ff8
8 changed files with 244 additions and 0 deletions

64
tests/rackspace/helper.rb Normal file
View file

@ -0,0 +1,64 @@
module Rackspace
def self.[](service)
@@connections ||= Hash.new do |hash, key|
credentials = Fog.credentials.reject do |k, v|
![:rackspace_api_key, :rackspace_username].include?(k)
end
hash[key] = case key
when :files
Fog::Rackspace::Files.new(credentials)
when :servers
Fog::Rackspace::Servers.new(credentials)
end
end
@@connections[service]
end
module Files
module Formats
end
end
module Servers
module Formats
FLAVOR = {
'disk' => Integer,
'id' => Integer,
'name' => String,
'ram' => Integer
}
IMAGE = {
'id' => Integer,
'name' => String,
'serverId' => Integer,
'status' => String,
'updated' => String
}
SERVER = {
'addresses' => {
'private' => [String],
'public' => [String]
},
'flavorId' => Integer,
'hostId' => String,
'id' => Integer,
'imageId' => Integer,
'metadata' => {},
'name' => String,
'progress' => Integer,
'status' => String
}
end
end
end

View file

@ -0,0 +1,22 @@
Shindo.tests('Rackspace::Servers#create_image', 'rackspace') do
tests('success') do
before do
@server_id = Rackspace[:servers].create_server(1, 3, 'fogcreateserver').body['server']['id']
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
@data = Rackspace[:servers].create_image(@server_id).body['image']
@image_id = @data['id']
end
after do
Rackspace[:servers].delete_server(@server_id)
wait_for { Rackspace[:servers].get_image_details(@image_id).body['image']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_image(@image_id)
end
test('has proper output format') do
validate_format(@data, Rackspace::Servers::Formats::IMAGE)
end
end
end

View file

@ -0,0 +1,19 @@
Shindo.tests('Rackspace::Servers#create_server', 'rackspace') do
tests('success') do
before do
@data = Rackspace[:servers].create_server(1, 3, 'fogcreateserver').body['server']
@server_id = @data['id']
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end
test('has proper output format') do
validate_format(@data, Rackspace::Servers::Formats::SERVER.merge('adminPass' => String))
end
end
end

View file

@ -0,0 +1,32 @@
Shindo.tests('Rackspace::Servers#delete_image', 'rackspace') do
tests('success') do
before do
@server_id = Rackspace[:servers].create_server(1, 3, 'fogcreateserver').body['server']['id']
@image_id = Rackspace[:servers].create_image(@server_id).body['image']['id']
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end
test('has proper output format') do
wait_for { Rackspace[:servers].get_image_details(@image_id).body['image']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_image(@image_id)
end
end
tests('failure') do
test('raises NotFound error if image does not exist') do
begin
Rackspace[:servers].delete_image(0)
false
rescue Excon::Errors::NotFound
true
end
end
end
end

View file

@ -0,0 +1,26 @@
Shindo.tests('Rackspace::Servers#delete_server', 'rackspace') do
tests('success') do
before do
@server_id = Rackspace[:servers].create_server(1, 3, 'fogcreateserver').body['server']['id']
end
test('has proper output format') do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end
end
tests('failure') do
test('raises NotFound error if server does not exist') do
begin
Rackspace[:servers].delete_server(0)
false
rescue Excon::Errors::NotFound
true
end
end
end
end

View file

@ -0,0 +1,25 @@
Shindo.tests('Rackspace::Servers#get_flavor_details', 'rackspace') do
tests('success') do
before do
@data = Rackspace[:servers].get_flavor_details(1).body['flavor']
end
test('has proper output format') do
validate_format(@data, Rackspace::Servers::Formats::FLAVOR)
end
end
tests('failure') do
test('raises NotFound error if flavor does not exist') do
begin
Rackspace[:servers].get_flavor_details(0)
false
rescue Excon::Errors::NotFound
true
end
end
end
end

View file

@ -0,0 +1,25 @@
Shindo.tests('Rackspace::Servers#get_image_details', 'rackspace') do
tests('success') do
before do
@data = Rackspace[:servers].get_image_details(3).body['image']
end
test('has proper output format') do
validate_format(@data, Rackspace::Servers::Formats::IMAGE)
end
end
tests('failure') do
test('raises NotFound error if image does not exist') do
begin
Rackspace[:servers].get_image_details(0)
false
rescue Excon::Errors::NotFound
true
end
end
end
end

View file

@ -0,0 +1,31 @@
Shindo.tests('Rackspace::Servers#get_server_details', 'rackspace') do
tests('success') do
before do
@server_id = Rackspace[:servers].create_server(1, 3, 'fogcreateserver').body['server']['id']
@data = Rackspace[:servers].get_server_details(@server_id).body['server']
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end
test('has proper output format') do
validate_format(@data, Rackspace::Servers::Formats::SERVER)
end
end
tests('failure') do
test('raises NotFound error if server does not exist') do
begin
Rackspace[:servers].get_server_details(0)
false
rescue Excon::Errors::NotFound
true
end
end
end
end