2024-06-09 22:16:20 -04:00
|
|
|
module RubyQA
|
|
|
|
require 'erb'
|
|
|
|
class Test
|
|
|
|
DEFAULT_OPTIONS={
|
|
|
|
:site => "",
|
|
|
|
:cluster => false,
|
|
|
|
:has_key => "",
|
2024-06-28 21:14:07 -04:00
|
|
|
:template => nil,
|
2024-06-09 22:16:20 -04:00
|
|
|
}.freeze
|
|
|
|
|
|
|
|
attr_reader :name, :options, :proc
|
|
|
|
|
2024-12-11 11:25:13 -05:00
|
|
|
def initialize (name, options = {}, &test_block)
|
2024-06-09 22:16:20 -04:00
|
|
|
@tests = Hash.new
|
|
|
|
@name = name
|
|
|
|
@options = DEFAULT_OPTIONS.merge(options)
|
|
|
|
@test = test_block
|
|
|
|
@description = ""
|
2024-06-28 21:14:07 -04:00
|
|
|
if @options[:description]
|
2024-06-09 22:16:20 -04:00
|
|
|
@description=options[:description]
|
2024-06-28 21:14:07 -04:00
|
|
|
@options.delete(:description)
|
|
|
|
end
|
|
|
|
if @options.has_key? :template
|
|
|
|
@template = @options[:template]
|
|
|
|
@options.delete(:template)
|
2024-06-09 22:16:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_host(host)
|
|
|
|
## By default if options weren't changed, then
|
|
|
|
## we just assume it is to be tested against all
|
|
|
|
## provided hosts
|
|
|
|
is_valid = 0
|
|
|
|
if @options == DEFAULT_OPTIONS
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
DEFAULT_OPTIONS.each do |key,value|
|
|
|
|
if @options[key] != value and host[key] != @options[key]
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
def run (host)
|
|
|
|
test_status = "N/A"
|
2024-06-28 21:14:07 -04:00
|
|
|
context = Hash.new
|
|
|
|
if @test.call(host, context)
|
2024-12-11 11:25:13 -05:00
|
|
|
test_status = "PASSED".green
|
2024-06-09 22:16:20 -04:00
|
|
|
else
|
2024-12-11 11:25:13 -05:00
|
|
|
test_status = "FAILED".red
|
2024-06-09 22:16:20 -04:00
|
|
|
end
|
2024-06-28 21:14:07 -04:00
|
|
|
@tests[host.name]={
|
|
|
|
:host => host,
|
|
|
|
:status => test_status,
|
|
|
|
:context => context
|
|
|
|
}
|
2024-06-09 22:16:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def report
|
|
|
|
if @tests.count == 0
|
|
|
|
return
|
|
|
|
end
|
2024-06-28 21:14:07 -04:00
|
|
|
|
|
|
|
if @template.nil?
|
2024-12-11 11:25:13 -05:00
|
|
|
self.render
|
|
|
|
else
|
|
|
|
@template.result(binding)
|
|
|
|
end
|
2024-06-09 22:16:20 -04:00
|
|
|
end
|
|
|
|
end
|
2024-12-11 11:25:13 -05:00
|
|
|
RubyQA::Template::BASE_TEST_TEMPLATE.def_method(RubyQA::Test, 'render')
|
|
|
|
|
2024-06-09 22:16:20 -04:00
|
|
|
end
|
|
|
|
|