Skip to content

Commit 3107104

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 3107104

File tree

2 files changed

+62
-46
lines changed

2 files changed

+62
-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: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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'
312
require 'simp/rspec-puppet-facts'
@@ -7,34 +16,31 @@
716

817
# RSpec Material
918
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
19+
module_name = File.basename(File.expand_path(File.join(__FILE__, '../..')))
1820

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'
21+
if ENV['PUPPET_DEBUG']
22+
Puppet::Util::Log.level = :debug
23+
Puppet::Util::Log.newdestination(:console)
2324
end
2425

25-
default_hiera_config =<<-EOM
26+
default_hiera_config = <<~HIERA_CONFIG
2627
---
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
28+
version: 5
29+
hierarchy:
30+
- name: SIMP Compliance Engine
31+
lookup_key: compliance_markup::enforcement
32+
options:
33+
enabled_sce_versions: [2]
34+
- name: Custom Test Hiera
35+
path: "%{custom_hiera}.yaml"
36+
- name: "%{module_name}"
37+
path: "%{module_name}.yaml"
38+
- name: Common
39+
path: default.yaml
40+
defaults:
41+
data_hash: yaml_data
42+
datadir: "stub"
43+
HIERA_CONFIG
3844

3945
# This can be used from inside your spec tests to set the testable environment.
4046
# You can use this to stub out an ENC.
@@ -47,7 +53,7 @@
4753
# end
4854
#
4955
def set_environment(environment = :production)
50-
RSpec.configure { |c| c.default_facts['environment'] = environment.to_s }
56+
RSpec.configure { |c| c.default_facts['environment'] = environment.to_s }
5157
end
5258

5359
# This can be used from inside your spec tests to load custom hieradata within
@@ -69,39 +75,39 @@ def set_environment(environment = :production)
6975
#
7076
# Note: Any colons (:) are replaced with underscores (_) in the class name.
7177
def set_hieradata(hieradata)
72-
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
78+
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
7379
end
7480

75-
if not File.directory?(File.join(fixture_path,'hieradata')) then
76-
FileUtils.mkdir_p(File.join(fixture_path,'hieradata'))
81+
unless File.directory?(File.join(fixture_path, 'hieradata'))
82+
FileUtils.mkdir_p(File.join(fixture_path, 'hieradata'))
7783
end
7884

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

8389
RSpec.configure do |c|
8490
# If nothing else...
8591
c.default_facts = {
86-
:production => {
92+
production: {
8793
#:fqdn => 'production.rspec.test.localdomain',
88-
:path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
89-
:concat_basedir => '/tmp'
94+
path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
95+
concat_basedir: '/tmp'
9096
}
9197
}
9298

9399
c.mock_framework = :rspec
94-
c.mock_with :mocha
100+
c.mock_with :rspec
95101

96102
c.module_path = File.join(fixture_path, 'modules')
97103
c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir)
98104

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

101107
# Useless backtrace noise
102108
backtrace_exclusion_patterns = [
103-
/spec_helper/,
104-
/gems/
109+
%r{spec_helper},
110+
%r{gems},
105111
]
106112

107113
if c.respond_to?(:backtrace_exclusion_patterns)
@@ -110,21 +116,31 @@ def set_hieradata(hieradata)
110116
c.backtrace_clean_patterns = backtrace_exclusion_patterns
111117
end
112118

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

117132
File.open(c.hiera_config, 'w') do |f|
118133
f.write data.to_yaml
119134
end
120135
end
136+
# rubocop:enable RSpec/BeforeAfterAll
121137

122138
c.before(:each) do
123139
@spec_global_env_temp = Dir.mktmpdir('simpspec')
124140

125141
if defined?(environment)
126142
set_environment(environment)
127-
FileUtils.mkdir_p(File.join(@spec_global_env_temp,environment.to_s))
143+
FileUtils.mkdir_p(File.join(@spec_global_env_temp, environment.to_s))
128144
end
129145

130146
# ensure the user running these tests has an accessible environmentpath
@@ -135,9 +151,9 @@ def set_hieradata(hieradata)
135151

136152
# sanitize hieradata
137153
if defined?(hieradata)
138-
set_hieradata(hieradata.gsub(':','_'))
154+
set_hieradata(hieradata.gsub(':', '_'))
139155
elsif defined?(class_name)
140-
set_hieradata(class_name.gsub(':','_'))
156+
set_hieradata(class_name.gsub(':', '_'))
141157
end
142158
end
143159

@@ -151,7 +167,7 @@ def set_hieradata(hieradata)
151167
Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir|
152168
begin
153169
Pathname.new(dir).realpath
154-
rescue
155-
fail "ERROR: The module '#{dir}' is not installed. Tests cannot continue."
170+
rescue StandardError
171+
raise "ERROR: The module '#{dir}' is not installed. Tests cannot continue."
156172
end
157173
end

0 commit comments

Comments
 (0)