Added unit tests, only took most of the night :)

This commit is contained in:
username-is-already-taken2 2016-11-18 23:32:52 +00:00
parent b6b4525379
commit e6e47eec4c
4 changed files with 29 additions and 1 deletions

View file

@ -262,7 +262,11 @@ class MockLoader
'hostname' => cmd.call('hostname'), 'hostname' => cmd.call('hostname'),
# hostname windows # hostname windows
'$env:computername' => cmd.call('$env-computername'), '$env:computername' => cmd.call('$env-computername'),
} # windows_task doesnt exist
"schtasks /query /v /fo csv /tn 'does-not-exist' | ConvertFrom-Csv | Select @{N='URI';E={$_.TaskName}},@{N='State';E={$_.Status.ToString()}},'Logon Mode','Last Result','Task To Run','Run As User','Scheduled Task State' | ConvertTo-Json -Compress" => cmd.call('schtasks-error'),
# windows_task exist
"schtasks /query /v /fo csv /tn 'WeLovePizza' | ConvertFrom-Csv | Select @{N='URI';E={$_.TaskName}},@{N='State';E={$_.Status.ToString()}},'Logon Mode','Last Result','Task To Run','Run As User','Scheduled Task State' | ConvertTo-Json -Compress" => cmd.call('schtasks-success'),
}
@backend @backend
end end

View file

@ -0,0 +1 @@
ERROR: The system cannot find the path specified.

View file

@ -0,0 +1 @@
{"URI":"\\Microsoft\\Windows\\Time Synchronization\\SynchronizeTime","State":"Ready","Logon Mode":"Interactive/Background","Last Result":"1056","Task To Run":"%windir%\\system32\\sc.exe start w32time task_started","Run As User":"LOCAL SERVICE","Scheduled Task State":"Enabled"}

View file

@ -0,0 +1,22 @@
# author: Gary Bright
# author: Chris Beard
require 'helper'
require 'inspec/resource'
describe 'Inspec::Resources::WindowsTasks' do
it 'verify parsing a windows task that does not exist' do
resource_fail = MockLoader.new(:windows).load_resource('windows_task', 'does-not-exist')
_(resource_fail.exists?).must_equal false
end
it 'verify parsing a windows task which is valid' do
resource = MockLoader.new(:windows).load_resource('windows_task', 'WeLovePizza')
_(resource.enabled?).must_equal true
_(resource.disabled?).must_equal false
_(resource.logon_mode).must_equal 'Interactive/Background'
_(resource.last_result).must_equal '1056'
_(resource.task_to_run).must_equal '%windir%\\system32\\sc.exe start w32time task_started'
_(resource.run_as_user).must_equal 'LOCAL SERVICE'
_(resource.type).must_equal 'windows-task'
_(resource.to_s).must_equal "Windows Task 'WeLovePizza'"
end
end