mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
Added unit tests, only took most of the night :)
This commit is contained in:
parent
b6b4525379
commit
e6e47eec4c
4 changed files with 29 additions and 1 deletions
|
@ -262,7 +262,11 @@ class MockLoader
|
|||
'hostname' => cmd.call('hostname'),
|
||||
# hostname windows
|
||||
'$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
|
||||
end
|
||||
|
|
1
test/unit/mock/cmd/schtasks-error
Normal file
1
test/unit/mock/cmd/schtasks-error
Normal file
|
@ -0,0 +1 @@
|
|||
ERROR: The system cannot find the path specified.
|
1
test/unit/mock/cmd/schtasks-success
Normal file
1
test/unit/mock/cmd/schtasks-success
Normal 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"}
|
22
test/unit/resources/windows_task_test.rb
Normal file
22
test/unit/resources/windows_task_test.rb
Normal 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
|
Loading…
Reference in a new issue