Skip to content

Commit 524b883

Browse files
authored
[puppetsync] Don't ignore Puppet 8 failures (#112)
1 parent 9c85734 commit 524b883

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
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: 38 additions & 32 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,27 +16,21 @@
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
18-
19+
module_name = File.basename(File.expand_path(File.join(__FILE__, '../..')))
1920

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
---
2728
version: 5
2829
hierarchy:
2930
- name: SIMP Compliance Engine
3031
lookup_key: compliance_markup::enforcement
32+
options:
33+
enabled_sce_versions: [2]
3134
- name: Custom Test Hiera
3235
path: "%{custom_hiera}.yaml"
3336
- name: "%{module_name}"
@@ -37,7 +40,7 @@
3740
defaults:
3841
data_hash: yaml_data
3942
datadir: "stub"
40-
EOM
43+
HIERA_CONFIG
4144

4245
# This can be used from inside your spec tests to set the testable environment.
4346
# You can use this to stub out an ENC.
@@ -75,36 +78,36 @@ def set_hieradata(hieradata)
7578
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
7679
end
7780

78-
if not File.directory?(File.join(fixture_path,'hieradata')) then
79-
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'))
8083
end
8184

82-
if not File.directory?(File.join(fixture_path,'modules',module_name)) then
83-
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))
8487
end
8588

8689
RSpec.configure do |c|
8790
# If nothing else...
8891
c.default_facts = {
89-
:production => {
92+
production: {
9093
#:fqdn => 'production.rspec.test.localdomain',
91-
:path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
92-
:concat_basedir => '/tmp'
94+
path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
95+
concat_basedir: '/tmp'
9396
}
9497
}
9598

9699
c.mock_framework = :rspec
97-
c.mock_with :mocha
100+
c.mock_with :rspec
98101

99102
c.module_path = File.join(fixture_path, 'modules')
100103
c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir)
101104

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

104107
# Useless backtrace noise
105108
backtrace_exclusion_patterns = [
106-
/spec_helper/,
107-
/gems/
109+
%r{spec_helper},
110+
%r{gems},
108111
]
109112

110113
if c.respond_to?(:backtrace_exclusion_patterns)
@@ -113,9 +116,10 @@ def set_hieradata(hieradata)
113116
c.backtrace_clean_patterns = backtrace_exclusion_patterns
114117
end
115118

119+
# rubocop:disable RSpec/BeforeAfterAll
116120
c.before(:all) do
117-
data = YAML.load(default_hiera_config)
118-
data.keys.each do |key|
121+
data = YAML.safe_load(default_hiera_config)
122+
data.each_key do |key|
119123
next unless data[key].is_a?(Hash)
120124

121125
if data[key][:datadir] == 'stub'
@@ -129,25 +133,27 @@ def set_hieradata(hieradata)
129133
f.write data.to_yaml
130134
end
131135
end
136+
# rubocop:enable RSpec/BeforeAfterAll
132137

133138
c.before(:each) do
134139
@spec_global_env_temp = Dir.mktmpdir('simpspec')
135140

136141
if defined?(environment)
137142
set_environment(environment)
138-
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))
139144
end
140145

141146
# ensure the user running these tests has an accessible environmentpath
147+
Puppet[:digest_algorithm] = 'sha256'
142148
Puppet[:environmentpath] = @spec_global_env_temp
143149
Puppet[:user] = Etc.getpwuid(Process.uid).name
144150
Puppet[:group] = Etc.getgrgid(Process.gid).name
145151

146152
# sanitize hieradata
147153
if defined?(hieradata)
148-
set_hieradata(hieradata.gsub(':','_'))
154+
set_hieradata(hieradata.gsub(':', '_'))
149155
elsif defined?(class_name)
150-
set_hieradata(class_name.gsub(':','_'))
156+
set_hieradata(class_name.gsub(':', '_'))
151157
end
152158
end
153159

@@ -161,7 +167,7 @@ def set_hieradata(hieradata)
161167
Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir|
162168
begin
163169
Pathname.new(dir).realpath
164-
rescue
165-
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."
166172
end
167173
end

0 commit comments

Comments
 (0)