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

71 lines
2.2 KiB
Ruby
Executable file

require 'rubygems'
require 'shindo'
require File.join(File.dirname(__FILE__), '..', 'lib', 'fog')
require File.join(File.dirname(__FILE__), '..', 'tests', 'helper')
Shindo.tests('compute examples', 'compute') do
# iterate over all the providers
Fog.providers.each do |provider|
# FIXME: implement expected shared compute stuff for these providers as well
next if ['Bluebox', 'Brightbox', 'Ecloud', 'GoGrid', 'Linode', 'NewServers', 'Ninefold', 'Slicehost', 'StormOnDemand', 'VirtualBox', 'Voxel'].include?(provider)
provider = eval(provider) # convert from string to object
# skip if provider does not have compute
next unless provider.respond_to?(:services) && provider.services.include?(:compute)
tests(provider, provider.to_s.downcase) do
# use shortcuts to instantiate connection
@compute = Fog::Compute.new(:provider => provider.to_s)
# create a server
tests('@server = @compute.servers.bootstrap').succeeds do
@server = @compute.servers.bootstrap
end
# list servers
tests('@servers = @compute.servers').succeeds do
@servers = @compute.servers
end
# get a server
tests('@compute.servers.get(@server.identity)').succeeds do
@compute.servers.get(@server.identity)
end
# ssh to a server
tests('@server.ssh("pwd")').succeeds do
@server.ssh('pwd')
end
# scp a file to a server
lorem_path = File.join([File.dirname(__FILE__), '..', 'tests', 'lorem.txt'])
tests("@server.scp('#{lorem_path}', 'lorem.txt')").succeeds do
@server.scp(lorem_path, 'lorem.txt')
end
# scp a directory to a server
Dir.mkdir('/tmp/lorem')
file = ::File.new('/tmp/lorem/lorem.txt', 'w')
file.write(File.read(lorem_path))
lorem_dir = File.join([File.dirname(__FILE__), '..', 'tests'])
tests("@server.scp('#{lorem_dir}', '/tmp/lorem', :recursive => true)").succeeds do
@server.scp(lorem_dir, '/tmp/lorem', :recursive => true)
end
File.delete('/tmp/lorem/lorem.txt')
Dir.rmdir('/tmp/lorem')
# destroy the server
tests('@server.destroy').succeeds do
@server.destroy
end
end
end
end