Module: Beaker::DSL::Assertions
- Defined in:
- lib/beaker-windows/path.rb,
lib/beaker-windows/windows_feature.rb
Instance Method Summary collapse
-
#assert_win_path_on(host, path, path_type = :any) ⇒ Object
Assert that a Windows file/registry path is valid on a host.
-
#assert_windows_feature_on(host, feature_name, opts = {}) ⇒ Object
Assert that a Windows feature is installed or not on a host.
Instance Method Details
#assert_win_path_on(host, path, path_type = :any) ⇒ Object
Assert that a Windows file/registry path is valid on a host.
Attributes
-
host- A Windows Beaker 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’)
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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_windows_feature_on(host, feature_name, opts = {}) ⇒ Object
Assert that a Windows feature is installed or not on a host.
Attributes
-
host- A Windows Beaker 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)
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# 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 |