Class: Kitchen::Verifier::Pester

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/verifier/pester.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Pester

Creates a new Verifier object using the provided configuration data which will be merged with any default configuration.

Parameters:

  • config (Hash) (defaults to: {})

    provided verifier configuration



38
39
40
# File 'lib/kitchen/verifier/pester.rb', line 38

def initialize(config = {})
  init_config(config)
end

Instance Method Details

#create_sandboxObject

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:

Examples:

overriding #create_sandbox


class MyVerifier < Kitchen::Verifier::Base
  def create_sandbox
    super
    # any further file copies, preparations, etc.
  end
end


60
61
62
63
# File 'lib/kitchen/verifier/pester.rb', line 60

def create_sandbox
  super
  prepare_pester_tests
end

#init_commandString

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.

Returns:

  • (String)

    a command string



92
93
94
# File 'lib/kitchen/verifier/pester.rb', line 92

def init_command
  restart_winrm_service if config[:restart_winrm]
end

#install_commandString

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.

Returns:

  • (String)

    a command string



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_filesArray<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.

Returns:

  • (Array<String>)

    array of suite files



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_commandString

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.

Returns:

  • (String)

    a command string



102
103
# File 'lib/kitchen/verifier/pester.rb', line 102

def prepare_command
end

#prepare_pester_testsObject

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_serviceObject

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_commandString

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.

Returns:

  • (String)

    a command string



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_dirString

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.

Returns:

  • (String)

    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