Beaker helper library for testing on Windows.
Add this line to your application's Gemfile:
gem 'beaker-windows'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install beaker-windows
Join paths together with a "" Windows style path separator. This method will accept path segments with mixed separators as well as leading and trailing separators. Optionally you can specify to use an alternate path separator or strip the drive letter off the combined path.
join_path('c:\dog', 'bark')
join_path('c:\dog', 'bark', :path_sep => '/')
join_path('c:\dog', 'bark', :path_sep => '/', :strip_drive => true)
Executes a PowerShell command on a host. Allow validation of command execution and fail if PowerShell command throws an exception. Note: if quotes are required then the single quote should be preferred. If double quotes are required you will need to double escape the quotes!
on(hosts, exec_ps_cmd("Set-Content -path 'fu.txt' -value 'fu'"))
You can specify custom PowerShell options.
on(hosts, exec_ps_cmd("Set-Content -path 'fu.txt' -value 'fu'", :ExecutionPolicy => 'Unrestricted')
Encode a command that contains nested quotes or Unicode.
on(hosts, exec_ps_cmd("Set Content -path 'fu.txt', -value 'fu'", :EncodedCommand => true))
Wrap the PowerShell command to guarantee an exit code of "1" if the command fails.
on(hosts, exec_ps_cmd("1 -eq 2", :verify_cmd => true))
If the command throws an exception then it should exit with "1". (Default)
on(hosts, exec_ps_cmd("does.not.exist", :excep_fail => true))
Execute a PowerShell script on a remote machine. (This method supports native Unicode) Note: This method fails on Windows 2008 R2! See BKR-293 for more details.
exec_ps_script_on(host, 'Write-Host Hello')
Can also be used in a block for granular verification.
exec_ps_script_on(hosts, 'Write-Host Hello') do |result|
assert_match(/Hello/, result.stdout)
end
Get a list (returns an Array) of Windows features on a host. Allow for filtering of installed or available features.
Get all features regardless of installation state.
get_windows_features_on(host)
Filter for installed features.
get_windows_features_on(host, :filter => :installed)
Filter for available features.
get_windows_features_on(host, :filter => :available)
Install a Windows role or feature on a host.
install_windows_feature_on(host, 'Print-Server')
Optionally failures can be suppressed which allows for delayed verification of feature installation. (See assert_windows_feature_on for more details.)
install_windows_feature_on(host, 'Bad-Feature', :suppress_fail => true)
Remove a Windows role or feature on a host.
remove_windows_feature_on(host, 'Print-Server')
Optionally failures can be suppressed which allows for delayed verification of feature removal. (See assert_windows_feature_on for more details.)
remove_windows_feature_on(host, 'Bad-Feature', :suppress_fail => true)
Assert that a Windows feature is installed or not on a host. The advantage of this assert is that is will report as a Beaker test failure if the assertion fails.
Assert that a Windows feature is installed.
assert_windows_feature_on(host, 'Print-Server')
Assert that a Windows feature is available.
assert_windows_feature_on(host, 'WINS', :state => :available)
Get the data from a registry value.
get_registry_value_on(host, :hklm, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "SystemRoot")
Set the data for a registry value.
Set data for a REG_SZ registry value.
set_registry_value_on(host, :hkcu, 'SOFTWARE\test_key', 'string_value', 'test_data')
Set data for a REG_DWORD registry value.
set_registry_value_on(host, :hkcu, 'SOFTWARE\test_key', 'dword_value', 255, :dword)
Set data for a REG_BINARY registry value.
set_registry_value_on(host, :hkcu, 'SOFTWARE\test_key', 'bin_value', 'be,ef,f0,0d', :bin)
Remove a registry value.
remove_registry_value_on(host, :hkcu, 'SOFTWARE\test_key', 'string_value')
Create a new registry key. If the key already exists then this method will silently fail. This method will create parent intermediate parent keys if they do not exist.
new_registry_key_on(host, :hkcu, 'SOFTWARE\some_new_key')
Remove a registry key. The method will not remove a registry key if the key contains nested subkeys and values. Use the "recurse" argument to force deletion of nested registry keys.
remove_registry_key_on(host, :hkcu, 'SOFTWARE\test_key')