Class: Kitchen::Verifier::Pester
- Inherits:
-
Base
- Object
- Base
- Kitchen::Verifier::Pester
- Defined in:
- lib/kitchen/verifier/pester.rb
Instance Method Summary collapse
-
#create_sandbox ⇒ Object
Creates a temporary directory on the local workstation into which verifier related files and directories can be copied or created.
-
#init_command ⇒ String
Generates a command string which will perform any data initialization or configuration required after the verifier software is installed but before the sandbox has been transferred to the instance.
-
#initialize(config = {}) ⇒ Pester
constructor
Creates a new Verifier object using the provided configuration data which will be merged with any default configuration.
-
#install_command ⇒ String
Generates a command string which will install and configure the verifier software on an instance.
-
#local_suite_files ⇒ Array<String>
private
Returns an Array of test suite filenames for the related suite currently residing on the local workstation.
-
#prepare_command ⇒ String
Generates a command string which will perform any commands or configuration required just before the main verifier run command but after the sandbox has been transferred to the instance.
-
#prepare_pester_tests ⇒ Object
private
Copies all test suite files into the suites directory in the sandbox.
-
#restart_winrm_service ⇒ Object
private.
-
#run_command ⇒ String
Generates a command string which will invoke the main verifier command on the prepared instance.
-
#sandbox_suites_dir ⇒ String
private
Path to suites directory under sandbox path.
Constructor Details
#initialize(config = {}) ⇒ Pester
Creates a new Verifier object using the provided configuration data which will be merged with any default configuration.
38 39 40 |
# File 'lib/kitchen/verifier/pester.rb', line 38 def initialize(config = {}) init_config(config) end |
Instance Method Details
#create_sandbox ⇒ Object
Creates a temporary directory on the local workstation into which verifier related files and directories can be copied or created. The contents of this directory will be copied over to the instance before invoking the verifier’s run command. After this method completes, it is expected that the contents of the sandbox is complete and ready for copy to the remote instance.
Note: any subclasses would be well advised to call super first when overriding this method, for example:
60 61 62 63 |
# File 'lib/kitchen/verifier/pester.rb', line 60 def create_sandbox super prepare_pester_tests end |
#init_command ⇒ String
Generates a command string which will perform any data initialization or configuration required after the verifier software is installed but before the sandbox has been transferred to the instance. If no work is required, then nil will be returned.
92 93 94 |
# File 'lib/kitchen/verifier/pester.rb', line 92 def init_command restart_winrm_service if config[:restart_winrm] end |
#install_command ⇒ String
Generates a command string which will install and configure the verifier software on an instance. If no work is required, then nil will be returned.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kitchen/verifier/pester.rb', line 70 def install_command return if local_suite_files.empty? cmd = " set-executionpolicy unrestricted -force\n if (-not (get-module -list pester)) {\n if (-not (get-module PsGet)){\n iex (new-object Net.WebClient).DownloadString('http://bit.ly/GetPsGet')\n }\n Import-Module PsGet\n Install-Module Pester\n }\n CMD\n wrap_shell_code(Util.outdent!(cmd))\nend\n" |
#local_suite_files ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an Array of test suite filenames for the related suite currently residing on the local workstation. Any special provisioner-specific directories (such as a Chef roles/ directory) are excluded.
137 138 139 140 141 142 143 |
# File 'lib/kitchen/verifier/pester.rb', line 137 def local_suite_files base = File.join(config[:test_base_path], config[:suite_name]) glob = File.join(base, "*/**/*") Dir.glob(glob).reject do |f| File.directory?(f) end end |
#prepare_command ⇒ String
Generates a command string which will perform any commands or configuration required just before the main verifier run command but after the sandbox has been transferred to the instance. If no work is required, then nil will be returned.
102 103 |
# File 'lib/kitchen/verifier/pester.rb', line 102 def prepare_command end |
#prepare_pester_tests ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Copies all test suite files into the suites directory in the sandbox.
148 149 150 151 152 153 154 155 156 |
# File 'lib/kitchen/verifier/pester.rb', line 148 def prepare_pester_tests base = File.join(config[:test_base_path], config[:suite_name]) local_suite_files.each do |src| dest = File.join(sandbox_suites_dir, src.sub("#{base}/", "")) FileUtils.mkdir_p(File.dirname(dest)) FileUtils.cp(src, dest, :preserve => true) end end |
#restart_winrm_service ⇒ Object
private
122 123 124 125 126 127 128 |
# File 'lib/kitchen/verifier/pester.rb', line 122 def restart_winrm_service wrap_shell_code(Util.outdent!(" schtasks /Create /TN restart_winrm /TR \"powershell -command restart-service winrm\" /SC ONCE /ST 00:00\n schtasks /RUN /TN restart_winrm\n CMD\n ))\nend\n" |
#run_command ⇒ String
Generates a command string which will invoke the main verifier command on the prepared instance. If no work is required, then nil will be returned.
110 111 112 113 114 115 116 117 118 |
# File 'lib/kitchen/verifier/pester.rb', line 110 def run_command return if local_suite_files.empty? wrap_shell_code(Util.outdent!(" cd \"\#{File.join(config[:root_path],'suites/pester/' )}\"\n $global:ProgressPreference = 'SilentlyContinue'\n import-module Pester -force; invoke-pester -enableexit\n CMD\n ))\nend\n" |
#sandbox_suites_dir ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns path to suites directory under sandbox path.
160 161 162 |
# File 'lib/kitchen/verifier/pester.rb', line 160 def sandbox_suites_dir File.join(sandbox_path, "suites") end |