#!/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