lib/kitchen/verifier/pester.rb in kitchen-pester-0.9.1 vs lib/kitchen/verifier/pester.rb in kitchen-pester-0.10.0
- old
+ new
@@ -16,11 +16,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
require "pathname"
require "kitchen/verifier/base"
-require "kitchen/verifier/pester_version"
+require_relative "pester_version"
module Kitchen
module Verifier
@@ -31,10 +31,11 @@
plugin_version Kitchen::Verifier::PESTER_VERSION
default_config :restart_winrm, false
default_config :test_folder
default_config :use_local_pester_module, false
+ default_config :downloads, ["./PesterTestResults.xml"] => "./testresults"
# Creates a new Verifier object using the provided configuration data
# which will be merged with any default configuration.
#
# @param config [Hash] provided verifier configuration
@@ -106,19 +107,30 @@
return if local_suite_files.empty?
really_wrap_shell_code(run_command_script)
end
+ # Download functionality was added to the base verifier behavior after
+ # version 2.3.4
+ if Gem::Version.new(Kitchen::VERSION) <= Gem::Version.new("2.3.4")
+ def call(state)
+ super
+
+ download_test_files(state)
+ end
+ end
+
# private
def run_command_script
<<-CMD
- $TestPath = "#{config[:root_path]}";
- import-module Pester -force;
- $result = invoke-pester -path $testpath -passthru ;
- $result |
- export-clixml (join-path $testpath 'result.xml');
- $host.setshouldexit($result.failedcount)
+ Import-Module Pester -Force
+ $TestPath = "#{config[:root_path]}"
+ $OutputFilePath = $TestPath | Join-Path -ChildPath 'PesterTestResults.xml'
+
+ $result = Invoke-Pester -OutputFile $OutputFilePath -OutputFormat NUnitXml -Path $TestPath -Passthru
+ $result | Export-CliXml -Path (Join-Path -Path $TestPath -ChildPath 'result.xml')
+ $host.SetShouldExit($result.FailedCount)
CMD
end
def really_wrap_shell_code(code)
wrap_shell_code(Util.outdent!(use_local_powershell_modules(code)))
@@ -126,11 +138,11 @@
def use_local_powershell_modules(script)
<<-EOH
set-executionpolicy unrestricted -force;
$global:ProgressPreference = 'SilentlyContinue'
- $env:psmodulepath += ";$(join-path (resolve-path $env:temp).path 'verifier/modules')";
+ $env:psmodulepath += ";$(join-path (resolve-path $env:temp).path 'verifier/modules')"
#{script}
EOH
end
def install_command_script
@@ -226,9 +238,29 @@
wrap_shell_code(Util.outdent!(<<-CMD
#{cmd}
schtasks /RUN /TN restart_winrm
CMD
))
+ end
+
+ def download_test_files(state)
+ info("Downloading test result files from #{instance.to_str}")
+
+ instance.transport.connection(state) do |conn|
+ config[:downloads].to_h.each do |remotes, local|
+ debug("Downloading #{Array(remotes).join(", ")} to #{local}")
+
+ remotes.each do |file|
+ safe_name = instance.name.gsub(/[^0-9A-Z-]/i, "_")
+ local_path = File.join(local, safe_name, file)
+ remote_path = File.join(config[:root_path], file)
+
+ conn.download(remote_path, local_path)
+ end
+ end
+ end
+
+ debug("Finished downloading test result files from #{instance.to_str}")
end
# 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.