module Beaker::DSL::Assertions
Public Instance Methods
Assert that a Windows file/registry path is valid on a host.
Attributes¶ ↑
-
host
- A WindowsBeaker
host running PowerShell. -
path
- A path representing either a file system or registry path.If asserting registry paths they must be perpended with the correct hive.
-
path_type
- The type of path expected.-
:any
- Can be a container or leaf. (Default) -
:container
- Path must be a file system folder or registry key. -
:leaf
- Path must be a file system file or registry value.
-
Raises¶ ↑
ArgumentError
- An invalid path type specified. Minitest::Assertion
- Path does not exist or is the wrong type.
Example¶ ↑
assert_win_path_on
(host, ‘C:Windows’) assert_win_path_on
(host, ‘C:WindowsSystem32’, :container) assert_win_path_on
(host, ‘C:WindowsSystem32kernel32.dll’, :leaf) assert_win_path_on
(host, ‘HKLM:SOFTWAREMicrosoftWindows NTCurrentVersionSystemRoot’)
# File lib/beaker-windows/path.rb, line 85 def assert_win_path_on(host, path, path_type=:any) # Init ps_cmd = "Test-Path -Path '#{path}' -Type " # Expected path type case path_type when :any ps_cmd << 'Any' when :container ps_cmd << 'Container' when :leaf ps_cmd << 'Leaf' else raise(ArgumentError, 'An invalid path type specified!') end # Test path result = on(host, exec_ps_cmd(ps_cmd, :verify_cmd => true, :EncodedCommand => true), :accept_all_exit_codes => true) assert(0 == result.exit_code, 'Path does not exist or is the wrong type!') end
Assert that a Windows feature is installed or not on a host.
Attributes¶ ↑
-
host
- A WindowsBeaker
host running PowerShell 3 or greater. -
feature_name
- The name of the Windows feature to verify if installed.(NOT THE DISPLAY NAME!)
-
opts:state
- Assert the state of the Windows feature.-
:installed
- Feature is installed. (Default) -
:available
- Feature is not installed.
-
Raises¶ ↑
ArgumentError
- An invalid state was specified. Minitest::Assertion
- The feature is not in the desired state or does not exist.
Example¶ ↑
assert_windows_feature_on
(host, ‘Print-Server’) assert_windows_feature_on
(host, ‘WINS’, :state => :available) assert_windows_feature_on
(host, ‘Powershell-V2’, :state => :installed)
# File lib/beaker-windows/windows_feature.rb, line 153 def assert_windows_feature_on(host, feature_name, opts={}) # Init opts[:state] ||= :installed ps_cmd = "(Get-WindowsFeature -Name '#{feature_name}').InstallState -Eq " # Desired state case opts[:state] when :available ps_cmd << "'Available'" when :installed ps_cmd << "'Installed'" else raise(ArgumentError, 'Unknown feature state! Specify either :available or :installed.') end # Parse output result = on(host, exec_ps_cmd(ps_cmd), :accept_all_exit_codes => true) raise(RuntimeError, 'This method requires PowerShell 3 or greater!') if result.exit_code == 1 assert_match(/True/, result.stdout, 'The feature is not in the desired state or does not exist!') end