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.



16
17
18
19
20
21
22
23
# File 'lib/puppet-catalog-test/rake_task.rb', line 16

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

#exclude_patternObject

Returns the value of attribute exclude_pattern.



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

def exclude_pattern
  @exclude_pattern
end

#factsObject

Returns the value of attribute facts.



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

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.



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

def manifest_path
  @manifest_path
end

#module_pathsObject

Returns the value of attribute module_paths.



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

def module_paths
  @module_paths
end

#reporterObject

Returns the value of attribute reporter.



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

def reporter
  @reporter
end

#scenario_yamlObject

Returns the value of attribute scenario_yaml.



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

def scenario_yaml
  @scenario_yaml
end

Instance Method Details

#setupObject



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
50
51
52
53
54
55
56
57
# File 'lib/puppet-catalog-test/rake_task.rb', line 25

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

  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