Class: Abide::CLI::TestCommand

Inherits:
CmdParse::Command
  • Object
show all
Defined in:
lib/abide_dev_utils/cli/test.rb

Constant Summary collapse

CMD_NAME =
'test'
CMD_SHORT =
'Run test suites against a Puppet module'
CMD_LONG =
'Run various test suites against a Puppet module. Requires PDK to be installed.'
CMD_PDK =
'command -v pdk'
CMD_LIT_BASE =
'bundle exec rake'

Instance Method Summary collapse

Constructor Details

#initializeTestCommand

Returns a new instance of TestCommand.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/abide_dev_utils/cli/test.rb', line 12

def initialize
  super(CMD_NAME, takes_commands: false)
  short_desc(CMD_SHORT)
  long_desc(CMD_LONG)
  argument_desc(SUITE: 'Test suite to run [all, validate, unit, limus]')
  options.on('-p', '--puppet-version', 'Set Puppet version for unit tests. Takes SemVer string') { |p| @data[:puppet] = p }
  options.on('-e', '--pe-version', 'Set PE version for unit tests. Takes SemVer String') { |e| @data[:pe] = e }
  options.on('-n', '--no-teardown', 'Do not tear down Litmus machines after tests') { |_| @data[:no_teardown] = true }
  options.on('-c [puppet[67]]', '--collection [puppet[67]]', 'Puppet collection to use with litmus tests') { |c| @data[:collection] = c }
  options.on('-l [LIST]', '--provision-list [LIST]', 'Set the provision list for Litmus') { |l| @data[:provision_list] = l }
  options.on('-M [PATH]', '--module-dir [PATH]', 'Set a different directory as the module dir (defaults to current dir)') { |m| @data[:module_dir] = m }
  # Declare and setup commands
  @validate = ['validate', '--parallel']
  @unit = ['test', 'unit', '--parallel']
  # Add unit args if they exist
  @unit << "--puppet-version #{@data[:puppet]}" unless @data[:puppet].nil? && !@data[:pe].nil?
  @unit << "--pe-version #{@data[:pe]}" unless @data[:pe].nil?
  # Get litmus args and supply defaults if necessary
  litmus_pl = @data[:provision_list].nil? ? 'default' : @data[:provision_list]
  litmus_co = @data[:collection].nil? ? 'puppet6' : @data[:collection]
  # Now we craft the litmus commands
  @litmus_pr = [CMD_LIT_BASE, "'litmus:provision_list[#{litmus_pl}]'"]
  @litmus_ia = [CMD_LIT_BASE, "'litmus:install_agent[#{litmus_co}]'"]
  @litmus_im = [CMD_LIT_BASE, "'litmus:install_module'"]
  @litmus_ap = [CMD_LIT_BASE, "'litmus:acceptance:parallel'"]
  @litmus_td = [CMD_LIT_BASE, "'litmus:tear_down'"]
end

Instance Method Details

#execute(suite) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/abide_dev_utils/cli/test.rb', line 40

def execute(suite)
  validate_env_and_opts
  case suite.downcase
  when /^a[A-Za-z]*/
    run_command(@validate)
    run_command(@unit)
    run_litmus
  when /^v[A-Za-z]*/
    run_command(@validate)
  when /^u[A-Za-z]*/
    run_command(@unit)
  when /^l[A-Za-z]*/
    run_litmus
  else
    Abide::CLI::OUTPUT.simple("Suite #{suite} in invalid!")
    Abide::CLI::OUTPUT.simple('Valid options for TEST are [a]ll, [v]alidate, [u]nit, [l]itmus')
  end
end