Skip to content

Commit 6743e60

Browse files
committed
[puppetsync] Don't ignore Puppet 8 failures
Puppet 8 failures should not be ignored. Also * Use the correct Ruby version for Puppet 8 tests * Manage spec/spec_helper.rb in Puppet modules
1 parent 1dfb08b commit 6743e60

File tree

2 files changed

+63
-46
lines changed

2 files changed

+63
-46
lines changed

.github/workflows/pr_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ jobs:
115115
experimental: false
116116
- label: 'Puppet 8.x'
117117
puppet_version: '~> 8.0'
118-
ruby_version: 3.1
119-
experimental: true
118+
ruby_version: '3.2'
119+
experimental: false
120120
fail-fast: false
121121
env:
122122
PUPPET_VERSION: ${{matrix.puppet.puppet_version}}

spec/spec_helper.rb

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1+
# frozen_string_literal: true
2+
#
3+
# ------------------------------------------------------------------------------
4+
# NOTICE: **This file is maintained with puppetsync**
5+
#
6+
# This file is automatically updated as part of a puppet module baseline.
7+
# The next baseline sync will overwrite any local changes made to this file.
8+
# ------------------------------------------------------------------------------
9+
110
require 'puppetlabs_spec_helper/module_spec_helper'
211
require 'rspec-puppet'
12+
require 'super_diff/rspec'
313
require 'simp/rspec-puppet-facts'
414
include Simp::RspecPuppetFacts
515

616
require 'pathname'
717

818
# RSpec Material
919
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
10-
module_name = File.basename(File.expand_path(File.join(__FILE__,'../..')))
11-
12-
# Add fixture lib dirs to LOAD_PATH. Work-around for PUP-3336
13-
if Puppet.version < "4.0.0"
14-
Dir["#{fixture_path}/modules/*/lib"].entries.each do |lib_dir|
15-
$LOAD_PATH << lib_dir
16-
end
17-
end
20+
module_name = File.basename(File.expand_path(File.join(__FILE__, '../..')))
1821

19-
20-
if !ENV.key?( 'TRUSTED_NODE_DATA' )
21-
warn '== WARNING: TRUSTED_NODE_DATA is unset, using TRUSTED_NODE_DATA=yes'
22-
ENV['TRUSTED_NODE_DATA']='yes'
22+
if ENV['PUPPET_DEBUG']
23+
Puppet::Util::Log.level = :debug
24+
Puppet::Util::Log.newdestination(:console)
2325
end
2426

25-
default_hiera_config =<<-EOM
27+
default_hiera_config = <<~HIERA_CONFIG
2628
---
27-
:backends:
28-
- "rspec"
29-
- "yaml"
30-
:yaml:
31-
:datadir: "stub"
32-
:hierarchy:
33-
- "%{custom_hiera}"
34-
- "%{spec_title}"
35-
- "%{module_name}"
36-
- "default"
37-
EOM
29+
version: 5
30+
hierarchy:
31+
- name: SIMP Compliance Engine
32+
lookup_key: compliance_markup::enforcement
33+
options:
34+
enabled_sce_versions: [2]
35+
- name: Custom Test Hiera
36+
path: "%{custom_hiera}.yaml"
37+
- name: "%{module_name}"
38+
path: "%{module_name}.yaml"
39+
- name: Common
40+
path: default.yaml
41+
defaults:
42+
data_hash: yaml_data
43+
datadir: "stub"
44+
HIERA_CONFIG
3845

3946
# This can be used from inside your spec tests to set the testable environment.
4047
# You can use this to stub out an ENC.
@@ -47,7 +54,7 @@
4754
# end
4855
#
4956
def set_environment(environment = :production)
50-
RSpec.configure { |c| c.default_facts['environment'] = environment.to_s }
57+
RSpec.configure { |c| c.default_facts['environment'] = environment.to_s }
5158
end
5259

5360
# This can be used from inside your spec tests to load custom hieradata within
@@ -69,39 +76,39 @@ def set_environment(environment = :production)
6976
#
7077
# Note: Any colons (:) are replaced with underscores (_) in the class name.
7178
def set_hieradata(hieradata)
72-
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
79+
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
7380
end
7481

75-
if not File.directory?(File.join(fixture_path,'hieradata')) then
76-
FileUtils.mkdir_p(File.join(fixture_path,'hieradata'))
82+
unless File.directory?(File.join(fixture_path, 'hieradata'))
83+
FileUtils.mkdir_p(File.join(fixture_path, 'hieradata'))
7784
end
7885

79-
if not File.directory?(File.join(fixture_path,'modules',module_name)) then
80-
FileUtils.mkdir_p(File.join(fixture_path,'modules',module_name))
86+
unless File.directory?(File.join(fixture_path, 'modules', module_name))
87+
FileUtils.mkdir_p(File.join(fixture_path, 'modules', module_name))
8188
end
8289

8390
RSpec.configure do |c|
8491
# If nothing else...
8592
c.default_facts = {
86-
:production => {
93+
production: {
8794
#:fqdn => 'production.rspec.test.localdomain',
88-
:path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
89-
:concat_basedir => '/tmp'
95+
path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
96+
concat_basedir: '/tmp'
9097
}
9198
}
9299

93100
c.mock_framework = :rspec
94-
c.mock_with :mocha
101+
c.mock_with :rspec
95102

96103
c.module_path = File.join(fixture_path, 'modules')
97104
c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir)
98105

99-
c.hiera_config = File.join(fixture_path,'hieradata','hiera.yaml')
106+
c.hiera_config = File.join(fixture_path, 'hieradata', 'hiera.yaml')
100107

101108
# Useless backtrace noise
102109
backtrace_exclusion_patterns = [
103-
/spec_helper/,
104-
/gems/
110+
%r{spec_helper},
111+
%r{gems},
105112
]
106113

107114
if c.respond_to?(:backtrace_exclusion_patterns)
@@ -110,21 +117,31 @@ def set_hieradata(hieradata)
110117
c.backtrace_clean_patterns = backtrace_exclusion_patterns
111118
end
112119

120+
# rubocop:disable RSpec/BeforeAfterAll
113121
c.before(:all) do
114-
data = YAML.load(default_hiera_config)
115-
data[:yaml][:datadir] = File.join(fixture_path, 'hieradata')
122+
data = YAML.safe_load(default_hiera_config)
123+
data.each_key do |key|
124+
next unless data[key].is_a?(Hash)
125+
126+
if data[key][:datadir] == 'stub'
127+
data[key][:datadir] = File.join(fixture_path, 'hieradata')
128+
elsif data[key]['datadir'] == 'stub'
129+
data[key]['datadir'] = File.join(fixture_path, 'hieradata')
130+
end
131+
end
116132

117133
File.open(c.hiera_config, 'w') do |f|
118134
f.write data.to_yaml
119135
end
120136
end
137+
# rubocop:enable RSpec/BeforeAfterAll
121138

122139
c.before(:each) do
123140
@spec_global_env_temp = Dir.mktmpdir('simpspec')
124141

125142
if defined?(environment)
126143
set_environment(environment)
127-
FileUtils.mkdir_p(File.join(@spec_global_env_temp,environment.to_s))
144+
FileUtils.mkdir_p(File.join(@spec_global_env_temp, environment.to_s))
128145
end
129146

130147
# ensure the user running these tests has an accessible environmentpath
@@ -135,9 +152,9 @@ def set_hieradata(hieradata)
135152

136153
# sanitize hieradata
137154
if defined?(hieradata)
138-
set_hieradata(hieradata.gsub(':','_'))
155+
set_hieradata(hieradata.gsub(':', '_'))
139156
elsif defined?(class_name)
140-
set_hieradata(class_name.gsub(':','_'))
157+
set_hieradata(class_name.gsub(':', '_'))
141158
end
142159
end
143160

@@ -151,7 +168,7 @@ def set_hieradata(hieradata)
151168
Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir|
152169
begin
153170
Pathname.new(dir).realpath
154-
rescue
155-
fail "ERROR: The module '#{dir}' is not installed. Tests cannot continue."
171+
rescue StandardError
172+
raise "ERROR: The module '#{dir}' is not installed. Tests cannot continue."
156173
end
157174
end

0 commit comments

Comments
 (0)