Class: PuppetCatalogTest::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/puppet-catalog-test/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &task_block) ⇒ RakeTask

Returns a new instance of RakeTask.



19
20
21
22
23
24
25
26
# File 'lib/puppet-catalog-test/rake_task.rb', line 19

def initialize(name, &task_block)
  desc "Compile all puppet catalogs" unless ::Rake.application.last_comment

  task name do
    task_block.call(self) if task_block
    setup
  end
end

Instance Attribute Details

#config_dirObject

Returns the value of attribute config_dir.



8
9
10
# File 'lib/puppet-catalog-test/rake_task.rb', line 8

def config_dir
  @config_dir
end

#exclude_patternObject

Returns the value of attribute exclude_pattern.



9
10
11
# File 'lib/puppet-catalog-test/rake_task.rb', line 9

def exclude_pattern
  @exclude_pattern
end

#factsObject

Returns the value of attribute facts.



10
11
12
# File 'lib/puppet-catalog-test/rake_task.rb', line 10

def facts
  @facts
end

#include_patternObject

Returns the value of attribute include_pattern.



11
12
13
# File 'lib/puppet-catalog-test/rake_task.rb', line 11

def include_pattern
  @include_pattern
end

#manifest_pathObject

Returns the value of attribute manifest_path.



12
13
14
# File 'lib/puppet-catalog-test/rake_task.rb', line 12

def manifest_path
  @manifest_path
end

#module_pathsObject

Returns the value of attribute module_paths.



13
14
15
# File 'lib/puppet-catalog-test/rake_task.rb', line 13

def module_paths
  @module_paths
end

#parserObject

Returns the value of attribute parser.



14
15
16
# File 'lib/puppet-catalog-test/rake_task.rb', line 14

def parser
  @parser
end

#reporterObject

Returns the value of attribute reporter.



15
16
17
# File 'lib/puppet-catalog-test/rake_task.rb', line 15

def reporter
  @reporter
end

#scenario_yamlObject

Returns the value of attribute scenario_yaml.



16
17
18
# File 'lib/puppet-catalog-test/rake_task.rb', line 16

def scenario_yaml
  @scenario_yaml
end

#verboseObject

Returns the value of attribute verbose.



17
18
19
# File 'lib/puppet-catalog-test/rake_task.rb', line 17

def verbose
  @verbose
end

Instance Method Details

#setupObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/puppet-catalog-test/rake_task.rb', line 28

def setup
  puppet_config = {
    :config_dir => @config_dir,
    :manifest_path => @manifest_path,
    :module_paths => @module_paths,
    :parser => @parser,
    :verbose => @verbose
  }

  if @config_dir
    puppet_config[:hiera_config] = File.join(@config_dir, "hiera.yaml")
  end

  pct = TestRunner.new(puppet_config)

  @filter = Filter.new

  @filter.include_pattern = @include_pattern if @include_pattern
  @filter.exclude_pattern = @exclude_pattern if @exclude_pattern

  if @scenario_yaml
    pct.load_scenario_yaml(@scenario_yaml, @filter)
  else
    nodes = pct.collect_puppet_nodes(@filter)
    test_facts = @facts || fallback_facts

    nodes.each do |nodename|
      facts = test_facts.merge({
        'hostname' => nodename,
        'fqdn' => "#{nodename}.localdomain"
      })

      pct.add_test_case(nodename, facts)
    end
  end

  pct.reporter = @reporter if @reporter

  pct.run_tests!
end