Class: Abide::CLI::TestCommand

Inherits:
AbideCommand
  • 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'

Constants included from AbideDevUtils::Config

AbideDevUtils::Config::DEFAULT_PATH

Instance Method Summary collapse

Methods inherited from AbideCommand

#deprecated?, #on_after_add

Methods included from AbideDevUtils::Config

config_section, #config_section, fetch, #fetch, to_h, #to_h

Constructor Details

#initializeTestCommand

Returns a new instance of TestCommand.



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
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/abide_dev_utils/cli/test.rb', line 14

def initialize
  super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false, deprecated: true)
  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') do |p|
    @data[:puppet] = p
  end
  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') do |_|
    @data[:no_teardown] = true
  end
  options.on('-c [puppet[67]]', '--collection [puppet[67]]', 'Puppet collection to use with litmus tests') do |c|
    @data[:collection] = c
  end
  options.on('-l [LIST]', '--provision-list [LIST]', 'Set the provision list for Litmus') do |l|
    @data[:provision_list] = l
  end
  options.on('-M [PATH]', '--module-dir [PATH]',
             'Set a different directory as the module dir (defaults to current dir)') do |m|
    @data[:module_dir] = m
  end
  # 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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/abide_dev_utils/cli/test.rb', line 51

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