diff --git a/lib/test b/lib/test deleted file mode 100644 index 9806aa7..0000000 --- a/lib/test +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env ruby - -require './rubyqa' - -include RubyQA -$Manager = Manager.new - -host = Host.new( - :ip => '127.0.0.1', - :user => 'tristan', - :cluster => true -) - -Manager.new_test("hostname in /etc/hostname") {|host| - hostname = host.exec('cat /etc/hostname').strip - facts = host.resources['facts'].data - facts['networking']['hostname'] == hostname -} - -Manager.new_test("hostname in /etc/hosts", :cluster => true ) {|host| - facts = host.resources['facts'].data - hostname = facts['networking']['hostname'] - hosts = host.exec('cat /etc/hosts') - match_regex = /127\.0\.0\.1.+#{hostname.downcase}/ - hosts.match? match_regex -} - -Manager.new_test("Has user tristan") do |host| - passwd_file = host.exec("cat /etc/passwd") - passwd_file.match? /tristan.*/ -end - - -$Manager.add_host(host) -$Manager.run_tests -$Manager.report diff --git a/lib/test.rb b/lib/test.rb index 28ea61a..3bf6cb1 100644 --- a/lib/test.rb +++ b/lib/test.rb @@ -5,6 +5,7 @@ module RubyQA :site => "", :cluster => false, :has_key => "", + :template => nil, }.freeze attr_reader :name, :options, :proc @@ -15,8 +16,13 @@ module RubyQA @options = DEFAULT_OPTIONS.merge(options) @test = test_block @description = "" - if options[:description] + if @options[:description] @description=options[:description] + @options.delete(:description) + end + if @options.has_key? :template + @template = @options[:template] + @options.delete(:template) end end @@ -40,30 +46,43 @@ module RubyQA def run (host) test_status = "N/A" - if @test.call(host) + context = Hash.new + if @test.call(host, context) test_status = "PASSED" else test_status = "FAILED" end - @tests[host.name]=test_status + @tests[host.name]={ + :host => host, + :status => test_status, + :context => context + } end def report if @tests.count == 0 return end + template = nil + + if @template.nil? template = ERB.new < '-' ============================================== Test : "<%= @name %>" -<% if not @description.empty? -%> -Description : "<%= @description %> +<% if not @description.empty? -%> +Description : "<%= @description %> <% end -%> ============================================== -<% @tests.each do |key,val| -%> -<%= key %> : <%= val %> +<% @tests.each do |key,data| -%> +<%= key %> : <%= data[:status] %> <% if data[:context].has_key? :note %> (<%= data[:context][:note] %>) <% end %> <% end -%> EOF + + else + template = @template + end + template.result(binding) end end