2010-11-22 02:44:44 -05:00
|
|
|
__DIR__ = File.dirname(__FILE__)
|
|
|
|
__LIB_DIR__ = File.join(__DIR__, '../lib')
|
|
|
|
|
|
|
|
[ __DIR__, __LIB_DIR__ ].each do |directory|
|
|
|
|
$LOAD_PATH.unshift directory unless
|
|
|
|
$LOAD_PATH.include?(directory) ||
|
|
|
|
$LOAD_PATH.include?(File.expand_path(directory))
|
|
|
|
end
|
|
|
|
|
2010-09-23 13:48:52 -04:00
|
|
|
require 'fog'
|
2010-09-29 16:22:30 -04:00
|
|
|
require 'fog/core/bin'
|
2010-11-04 14:12:44 -04:00
|
|
|
|
2010-11-22 02:44:44 -05:00
|
|
|
Fog.bin = true
|
2010-11-04 14:12:44 -04:00
|
|
|
|
2010-11-11 14:54:55 -05:00
|
|
|
require 'tests/helpers/collection_tests'
|
|
|
|
require 'tests/helpers/model_tests'
|
|
|
|
|
2010-11-12 02:01:18 -05:00
|
|
|
require 'tests/helpers/compute/flavors_tests'
|
|
|
|
require 'tests/helpers/compute/server_tests'
|
|
|
|
require 'tests/helpers/compute/servers_tests'
|
|
|
|
|
2010-11-04 14:12:44 -04:00
|
|
|
require 'tests/helpers/storage/directory_tests'
|
|
|
|
require 'tests/helpers/storage/directories_tests'
|
|
|
|
require 'tests/helpers/storage/file_tests'
|
|
|
|
require 'tests/helpers/storage/files_tests'
|
2010-07-18 19:05:23 -04:00
|
|
|
|
2010-11-21 09:02:34 -05:00
|
|
|
# Use so you can run in mock mode from the command line:
|
|
|
|
#
|
|
|
|
# FOG_MOCK=true fog
|
|
|
|
|
2010-05-06 00:40:21 -04:00
|
|
|
if ENV["FOG_MOCK"] == "true"
|
|
|
|
Fog.mock!
|
|
|
|
end
|
|
|
|
|
2010-11-22 20:49:27 -05:00
|
|
|
# check to see which credentials are available and add others to the skipped tags list
|
|
|
|
all_providers = ['aws', 'bluebox', 'brightbox', 'gogrid', 'google', 'linode', 'local', 'newservers', 'rackspace', 'slicehost', 'terremark']
|
|
|
|
available_providers = Fog.providers.map {|provider| provider.to_s.downcase}
|
|
|
|
for provider in (all_providers - available_providers)
|
|
|
|
Formatador.display_line("[yellow]Skipping tests for [bold]#{provider}[/] [yellow]due to lacking credentials (add some to '~/.fog' to run them)[/]")
|
|
|
|
Thread.current[:tags] << ('-' << provider)
|
|
|
|
end
|
|
|
|
|
2010-05-27 14:27:08 -04:00
|
|
|
# Boolean hax
|
|
|
|
module Fog
|
|
|
|
module Boolean
|
|
|
|
end
|
|
|
|
end
|
|
|
|
FalseClass.send(:include, Fog::Boolean)
|
|
|
|
TrueClass.send(:include, Fog::Boolean)
|
|
|
|
|
2010-10-12 21:07:36 -04:00
|
|
|
def lorem_file
|
|
|
|
File.open(File.dirname(__FILE__) + '/lorem.txt', 'r')
|
|
|
|
end
|
|
|
|
|
2010-05-21 17:43:29 -04:00
|
|
|
module Shindo
|
|
|
|
class Tests
|
2010-05-06 00:40:21 -04:00
|
|
|
|
2010-11-12 02:01:18 -05:00
|
|
|
def responds_to(method_names)
|
|
|
|
for method_name in [*method_names]
|
|
|
|
tests("#respond_to?(:#{method_name})").succeeds do
|
|
|
|
@instance.respond_to?(method_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def formats(format)
|
2010-05-21 17:43:29 -04:00
|
|
|
test('has proper format') do
|
2010-11-15 20:17:37 -05:00
|
|
|
formats_kernel(instance_eval(&Proc.new), format)
|
2010-05-21 17:43:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-12 02:01:18 -05:00
|
|
|
def succeeds
|
2010-05-21 17:43:29 -04:00
|
|
|
test('succeeds') do
|
2010-11-12 02:01:18 -05:00
|
|
|
instance_eval(&Proc.new)
|
2010-05-31 11:37:26 -04:00
|
|
|
true
|
2010-05-21 17:43:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def formats_kernel(original_data, original_format, original = true)
|
|
|
|
valid = true
|
|
|
|
data = original_data.dup
|
|
|
|
format = original_format.dup
|
2010-06-04 00:32:59 -04:00
|
|
|
if format.is_a?(Array)
|
|
|
|
data = {:element => data}
|
|
|
|
format = {:element => format}
|
|
|
|
end
|
2010-05-21 17:43:29 -04:00
|
|
|
for key, value in format
|
|
|
|
valid &&= data.has_key?(key)
|
|
|
|
datum = data.delete(key)
|
|
|
|
format.delete(key)
|
|
|
|
case value
|
|
|
|
when Array
|
|
|
|
valid &&= datum.is_a?(Array)
|
2010-05-27 14:27:08 -04:00
|
|
|
if datum.is_a?(Array)
|
|
|
|
for element in datum
|
|
|
|
type = value.first
|
|
|
|
if type.is_a?(Hash)
|
|
|
|
valid &&= formats_kernel({:element => element}, {:element => type}, false)
|
2010-06-10 14:43:21 -04:00
|
|
|
elsif type.nil?
|
|
|
|
p "#{key} => #{value}"
|
2010-05-27 14:27:08 -04:00
|
|
|
else
|
|
|
|
valid &&= element.is_a?(type)
|
|
|
|
end
|
2010-05-21 17:43:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
when Hash
|
|
|
|
valid &&= datum.is_a?(Hash)
|
|
|
|
valid &&= formats_kernel(datum, value, false)
|
2010-03-28 20:04:38 -04:00
|
|
|
else
|
2010-05-27 14:27:08 -04:00
|
|
|
p "#{key} => #{value}" unless datum.is_a?(value)
|
2010-05-21 17:43:29 -04:00
|
|
|
valid &&= datum.is_a?(value)
|
2010-03-28 20:04:38 -04:00
|
|
|
end
|
|
|
|
end
|
2010-05-27 14:27:08 -04:00
|
|
|
p data unless data.empty?
|
|
|
|
p format unless format.empty?
|
2010-05-21 17:43:29 -04:00
|
|
|
valid &&= data.empty? && format.empty?
|
|
|
|
if !valid && original
|
|
|
|
@message = "#{original_data.inspect} does not match #{original_format.inspect}"
|
|
|
|
end
|
|
|
|
valid
|
2010-03-28 20:04:38 -04:00
|
|
|
end
|
2010-05-21 17:43:29 -04:00
|
|
|
|
2010-03-28 20:04:38 -04:00
|
|
|
end
|
|
|
|
end
|