add unit tests

This commit is contained in:
Christoph Hartmann 2016-09-09 10:30:41 +02:00
parent 82a4e21cf7
commit e61f71143d
5 changed files with 33 additions and 2 deletions

View file

@ -11,15 +11,15 @@ module Inspec::Resources
end
"
# returns the hostname of the local system
def hostname
os = inspec.os
if os.linux?
inspec.command('hostname').stdout.chomp
elsif os.windows?
# windows hostname
inspec.powershell('$env:computername').stdout.chomp
else
return skip_resource 'The `system` resource is not supported on your OS yet.'
skip_resource 'The `sys_info.hostname` resource is not supported on your OS yet.'
end
end
end

View file

@ -254,6 +254,10 @@ class MockLoader
'netstat -an -f inet' => cmd.call('hpux-netstat-inet'),
#ipv6 ports on hpux
'netstat -an -f inet6' => cmd.call('hpux-netstat-inet6'),
# hostname linux
'hostname' => cmd.call('hostname'),
# hostname windows
'$env:computername' => cmd.call('$env-computername'),
}
@backend

View file

@ -0,0 +1 @@
WIN-CIV7VMLVHLD

View file

@ -0,0 +1 @@
example.com

View file

@ -0,0 +1,25 @@
# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
require 'helper'
require 'inspec/resource'
describe 'Inspec::Resources::SysInfo' do
describe 'sys_info' do
it 'check ssh config parsing for Ubuntu' do
resource = MockLoader.new(:ubuntu1504).load_resource('sys_info')
_(resource.hostname).must_equal 'example.com'
end
it 'check ssh config parsing for Ubuntu' do
resource = MockLoader.new(:windows).load_resource('sys_info')
_(resource.hostname).must_equal 'WIN-CIV7VMLVHLD'
end
it 'check ssh config parsing for freebsd' do
resource = MockLoader.new(:freebsd10).load_resource('sys_info')
_(resource.hostname).must_equal 'The `sys_info.hostname` resource is not supported on your OS yet.'
end
end
end