puppet-catalog-test 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6e460a3f5c3408505c299c277fc0821c7fa5079
4
- data.tar.gz: 7ab1aadfda8d38b318734bc6a57a3af30d095e35
3
+ metadata.gz: 8e9ab263a7f76de207203221229750145e1e6156
4
+ data.tar.gz: 3b7997d24939efe752837764a1f4b301911a660b
5
5
  SHA512:
6
- metadata.gz: 8ea372847d724e7e995c091f7d228af3432ec93a6095822e723a4c8dbc920100255ad6fcda494d43a1833ff5ff0e26144afa69589cdc78adeedd322d968b628d
7
- data.tar.gz: bc025b96bcd6647307b281796b963a7ea3754c2785e95dc8e3c1f32d6d82701162792d04e22728f74e77bc98ac54b02ffb5ce6c059e8ebeb8a052d8e00aab0dd
6
+ metadata.gz: 38b83be5d37831e9d8ace38ee45a5f487786051c951b58feaa9c5c8bcb341a39fa076b884ac07270eb2106fbf20edb7af372762640ec8d30f7833f9b1bf15917
7
+ data.tar.gz: 319a65c89712d418292cd90be394fc088245ed7435b0be4b2e5f53b18aa5b53ceeb010374a9641e79ce2680b5a0bc6ad98fb38ff59fa9ba05a2d35c4c74c1959
data/Rakefile CHANGED
@@ -2,6 +2,8 @@ require "rake/testtask"
2
2
  require "bundler/gem_tasks"
3
3
  require "puppet/version"
4
4
  require "rubygems"
5
+ require "yaml"
6
+ require "erb"
5
7
 
6
8
  desc "Clean workspace"
7
9
  task :clean do
@@ -71,4 +73,29 @@ task :test_integration do
71
73
  end
72
74
  end
73
75
 
76
+ task :generate_test_matrix do
77
+ # rbenv doesn't support fuzzy version matching, so we are using a good old mapping table
78
+ ruby_version_mapping = {
79
+ "1.8.7" => "1.8.7-p374",
80
+ "1.9.3" => "1.9.3-p551",
81
+ "2.0.0" => "2.0.0-p645"
82
+ }
83
+
84
+ config = YAML.load_file(".travis.yml")
85
+ checks = []
86
+
87
+ config["rvm"].each do |ruby_version|
88
+ config["env"].each do |env_var|
89
+ if !config["matrix"]["exclude"].detect { |ex| ex["rvm"] == ruby_version && ex["env"] == env_var }
90
+ puppet_version = env_var.match(/^PUPPET_VERSION=(.*)$/)[1]
91
+ mapped_ruby_version = ruby_version_mapping[ruby_version] || ruby_version
92
+ checks << "check #{mapped_ruby_version} #{puppet_version}"
93
+ end
94
+ end
95
+ end
96
+
97
+ template = ERB.new(File.read("run-all-tests.erb"))
98
+ File.open("run-all-tests", "w+") { |fp| fp.puts template.result(binding) }
99
+ end
100
+
74
101
  task :default => [:test, :test_integration]
@@ -3,6 +3,11 @@ require "puppet"
3
3
  module PuppetCatalogTest
4
4
  class BasePuppetAdapter
5
5
  def initialize(config)
6
+ @config = config
7
+ end
8
+
9
+ def init_config()
10
+ config = @config
6
11
  manifest_path = config[:manifest_path]
7
12
  module_paths = config[:module_paths]
8
13
  config_dir = config[:config_dir]
@@ -9,11 +9,15 @@ module PuppetCatalogTest
9
9
  require 'puppet/test/test_helper'
10
10
  parser = config[:parser]
11
11
 
12
+ init_config
13
+
12
14
  # initialize was added in 3.1.0
13
15
  if Gem::Version.new(version) > Gem::Version.new('3.1.0')
14
16
  Puppet::Test::TestHelper.initialize
15
17
  end
16
18
 
19
+ Puppet::Test::TestHelper.before_all_tests
20
+
17
21
  Puppet::Node::Environment.new.modules_by_path.each do |_, mod|
18
22
  mod.entries.each do |entry|
19
23
  ldir = entry.plugin_directory
@@ -39,8 +43,8 @@ module PuppetCatalogTest
39
43
 
40
44
  def compile(node)
41
45
  begin
42
- Puppet::Test::TestHelper.before_each_test
43
- Puppet::Parser::Compiler.compile(node)
46
+ catalog = Puppet::Parser::Compiler.compile(node)
47
+ validate_relationships(catalog)
44
48
  rescue => e
45
49
  raise e
46
50
  ensure
@@ -49,6 +53,8 @@ module PuppetCatalogTest
49
53
  end
50
54
 
51
55
  def create_node(hostname, facts)
56
+ Puppet::Test::TestHelper.before_each_test
57
+ init_config
52
58
  node = Puppet::Node.new(hostname)
53
59
  node.merge(facts)
54
60
  node
@@ -57,5 +63,40 @@ module PuppetCatalogTest
57
63
  def version
58
64
  Puppet::PUPPETVERSION
59
65
  end
66
+
67
+ def validate_relationships(catalog)
68
+ catalog.resources.each do |resource|
69
+ next unless resource.is_a?(Puppet::Resource)
70
+
71
+ resource.each do |param, value|
72
+ pclass = Puppet::Type.metaparamclass(param)
73
+ if !pclass.nil? && pclass < Puppet::Type::RelationshipMetaparam
74
+ next if value.is_a?(String)
75
+ check_if_resource_exists(catalog, resource, param, value)
76
+ end
77
+ end
78
+ end
79
+ nil
80
+ end
81
+
82
+ private
83
+
84
+ def check_if_resource_exists(catalog, resource, param, value)
85
+ case value
86
+ when Array
87
+ value.each { |v| check_if_resource_exists(catalog, resource, param, v) }
88
+ when Puppet::Resource
89
+ matching_resource = catalog.resources.find do |resource|
90
+ resource.type == value.type &&
91
+ (resource.title.to_s == value.title.to_s ||
92
+ resource[:name] == value.title ||
93
+ resource[:alias] == value.title)
94
+ end
95
+
96
+ unless matching_resource
97
+ fail "#{resource} has #{param} relationship to invalid resource #{value}"
98
+ end
99
+ end
100
+ end
60
101
  end
61
102
  end
@@ -28,6 +28,8 @@ module PuppetCatalogTest
28
28
  end
29
29
 
30
30
  def create_node(hostname, facts)
31
+ Puppet::Test::TestHelper.before_each_test
32
+ init_config
31
33
  node = Puppet::Node.new(hostname, :facts => Puppet::Node::Facts.new("facts", facts))
32
34
  node.merge(facts)
33
35
  node
@@ -35,7 +37,6 @@ module PuppetCatalogTest
35
37
 
36
38
  def compile(node)
37
39
  begin
38
- Puppet::Test::TestHelper.before_each_test
39
40
  Puppet::Parser::Compiler.compile(node)
40
41
  rescue => e
41
42
  raise e
@@ -11,6 +11,8 @@ module PuppetCatalogTest
11
11
  return Puppet3xAdapter.new(config)
12
12
  elsif Puppet.version.start_with?("4.")
13
13
  return Puppet4xAdapter.new(config)
14
+ elsif Puppet.version.start_with?("5.")
15
+ return Puppet4xAdapter.new(config)
14
16
  end
15
17
 
16
18
  raise RuntimeException, "Unsupported Puppet version detected (#{Puppet.version})"
@@ -17,7 +17,7 @@ module PuppetCatalogTest
17
17
  attr_accessor :verbose
18
18
 
19
19
  def initialize(name, &task_block)
20
- desc "Compile all puppet catalogs" unless ::Rake.application.last_comment
20
+ desc "Compile all puppet catalogs" unless ::Rake.application.last_description
21
21
 
22
22
  task name do
23
23
  task_block.call(self) if task_block
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'puppet-catalog-test'
3
- s.version = '0.4.2'
3
+ s.version = '0.4.3'
4
4
  s.homepage = 'https://github.com/invadersmustdie/puppet-catalog-test/'
5
5
  s.summary = 'Test all your puppet catalogs for compiler warnings and errors'
6
6
  s.description = 'Test all your puppet catalogs for compiler warnings and errors.'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-catalog-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rene Lengwinat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-20 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.5.1
98
+ rubygems_version: 2.6.11
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Test all your puppet catalogs for compiler warnings and errors