lib/kitchen/verifier/pester.rb in kitchen-pester-1.1.1 vs lib/kitchen/verifier/pester.rb in kitchen-pester-1.2.0

- old
+ new

@@ -64,17 +64,19 @@ default_config :install_modules, [] default_config :downloads, { "./PesterTestResults.xml" => "./testresults/" } default_config :copy_folders, [] default_config :sudo, false default_config :shell, nil + default_config :environment, {} # Creates a new Verifier object using the provided configuration data # which will be merged with any default configuration. # # @param config [Hash] provided verifier configuration def initialize(config = {}) init_config(config) + raise ClientError.new "Environment Variables must be specified as a hash, not a #{config[:environment].class}" unless config[:environment].is_a?(Hash) end # 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 @@ -186,10 +188,11 @@ def resolve_downloads_paths! info("Resolving Downloads path from config.") config[:downloads] = config[:downloads] .map do |source, destination| source = source.to_s + destination = destination.gsub("%{instance_name}", instance.name) info(" resolving remote source's absolute path.") unless source.match?('^/|^[a-zA-Z]:[\\/]') # is Absolute? info(" '#{source}' is a relative path, resolving to: #{File.join(config[:root_path], source)}") source = File.join(config[:root_path], source.to_s).to_s end @@ -199,11 +202,11 @@ end info(" Destination: #{destination}") if !File.directory?(File.dirname(destination)) FileUtils.mkdir_p(File.dirname(destination)) else - info(" Directory #{File.dirname(destination)} seem to exist.") + info(" Directory #{File.dirname(destination)} seems to exist.") end [ source, destination ] end nil # make sure we do not return anything @@ -238,10 +241,11 @@ $PesterModule = Import-Module -Name Pester -Force -ErrorAction Stop -PassThru $TestPath = Join-Path "#{config[:root_path]}" -ChildPath "suites" $OutputFilePath = Join-Path "#{config[:root_path]}" -ChildPath 'PesterTestResults.xml' + #{ps_environment(config[:environment])} if ($PesterModule.Version.Major -le 4) { Write-Host -Object "Invoke Pester with v$($PesterModule.Version) Options" $options = New-PesterOption -TestSuiteName "Pester - #{instance.to_str}" $defaultPesterParameters = @{ @@ -433,11 +437,13 @@ New-Item -ItemType Directory -Path '#{config[:root_path]}/modules' -Force -ErrorAction SilentlyContinue Set-Location -Path "#{config[:root_path]}" # Send the pwsh here string to the file kitchen_cmd.ps1 @' try { - Set-ExecutionPolicy Unrestricted -force + if (@('Bypass', 'Unrestricted') -notcontains (Get-ExecutionPolicy)) { + Set-ExecutionPolicy Unrestricted -Force -Scope Process + } } catch { $_ | Out-String | Write-Warning } #{Util.outdent!(use_local_powershell_modules(code))} @@ -611,9 +617,20 @@ else # When the object is not a string nor a hash or array, it will be quoted as a string. # In most cases, PS is smart enough to convert back to the type it needs. "'" + obj.to_s + "'" end + end + + # Creates environment variable assignments from a ruby map. + # + # @api private + def ps_environment(obj) + commands = obj.map do |k, v| + "$env:#{k} = '#{v}'" + end + + commands.join("\n") end # returns the path of the modules subfolder # in the sandbox, where PS Modules and folders will be copied to. #