inspec/test/integration/default/powershell_spec.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2016-03-18 14:47:00 +00:00
# encoding: utf-8
2016-05-10 17:23:11 +00:00
2016-08-12 08:19:35 +00:00
unless os.windows?
STDERR.puts "\033[1;33mTODO: Not running #{__FILE__} because we are not on Windows.\033[0m"
return
end
2016-05-10 17:23:11 +00:00
2016-03-18 14:47:00 +00:00
script = <<-EOH
Write-Output 'hello'
EOH
2016-03-18 22:22:15 +00:00
# Write-Output comes with a newline
2016-03-18 14:47:00 +00:00
describe powershell(script) do
2016-03-18 22:22:15 +00:00
its('stdout') { should eq "hello\r\n" }
its('stderr') { should eq '' }
2016-03-18 14:47:00 +00:00
end
2016-03-26 21:35:33 +00:00
# remove whitespace \r\n from stdout
describe powershell(script) do
its('strip') { should eq "hello" }
end
2016-03-18 22:22:15 +00:00
# legacy test with `script` resource
2016-03-18 14:47:00 +00:00
describe script(script) do
2016-03-18 22:22:15 +00:00
its('stdout') { should eq "hello\r\n" }
its('stderr') { should eq '' }
end
# -NoNewLine only works in powershell 5
# @see https://blogs.technet.microsoft.com/heyscriptingguy/2015/08/07/the-powershell-5-nonewline-parameter/
describe powershell("'hello' | Write-Host -NoNewLine") do
2016-03-18 14:47:00 +00:00
its('stdout') { should eq 'hello' }
2016-03-18 22:22:15 +00:00
its('stderr') { should eq '' }
end
# test stderr
describe powershell("Write-Error \"error\"") do
its('stdout') { should eq '' }
# this is an xml error for now, if the script is run via WinRM
# @see https://github.com/WinRb/WinRM/issues/106
# its('stderr') { should eq 'error' }
2016-03-18 14:47:00 +00:00
end