Skip to content

Commit c4b2f37

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 ea5f1e8 commit c4b2f37

File tree

2 files changed

+40
-50
lines changed

2 files changed

+40
-50
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 & 48 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,19 +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__,'../..')))
19+
module_name = File.basename(File.expand_path(File.join(__FILE__, '../..')))
1120

12-
if !ENV.key?( 'TRUSTED_NODE_DATA' )
13-
warn '== WARNING: TRUSTED_NODE_DATA is unset, using TRUSTED_NODE_DATA=yes'
14-
ENV['TRUSTED_NODE_DATA']='yes'
21+
if ENV['PUPPET_DEBUG']
22+
Puppet::Util::Log.level = :debug
23+
Puppet::Util::Log.newdestination(:console)
1524
end
1625

17-
default_hiera_config =<<-EOM
26+
default_hiera_config = <<~HIERA_CONFIG
1827
---
1928
version: 5
2029
hierarchy:
2130
- name: SIMP Compliance Engine
2231
lookup_key: compliance_markup::enforcement
32+
options:
33+
enabled_sce_versions: [2]
2334
- name: Custom Test Hiera
2435
path: "%{custom_hiera}.yaml"
2536
- name: "%{module_name}"
@@ -29,7 +40,7 @@
2940
defaults:
3041
data_hash: yaml_data
3142
datadir: "stub"
32-
EOM
43+
HIERA_CONFIG
3344

3445
# This can be used from inside your spec tests to set the testable environment.
3546
# You can use this to stub out an ENC.
@@ -67,38 +78,36 @@ def set_hieradata(hieradata)
6778
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
6879
end
6980

70-
if not File.directory?(File.join(fixture_path,'hieradata')) then
71-
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'))
7283
end
7384

74-
if not File.directory?(File.join(fixture_path,'modules',module_name)) then
75-
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))
7687
end
7788

7889
RSpec.configure do |c|
7990
# If nothing else...
8091
c.default_facts = {
81-
:production => {
92+
production: {
8293
#:fqdn => 'production.rspec.test.localdomain',
83-
:path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
84-
:concat_basedir => '/tmp'
94+
path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
95+
concat_basedir: '/tmp'
8596
}
8697
}
8798

88-
c.trusted_server_facts = true if c.respond_to?(:trusted_server_facts)
89-
9099
c.mock_framework = :rspec
91-
c.mock_with :mocha
100+
c.mock_with :rspec
92101

93102
c.module_path = File.join(fixture_path, 'modules')
94103
c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir)
95104

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

98107
# Useless backtrace noise
99108
backtrace_exclusion_patterns = [
100-
/spec_helper/,
101-
/gems/
109+
%r{spec_helper},
110+
%r{gems},
102111
]
103112

104113
if c.respond_to?(:backtrace_exclusion_patterns)
@@ -107,9 +116,10 @@ def set_hieradata(hieradata)
107116
c.backtrace_clean_patterns = backtrace_exclusion_patterns
108117
end
109118

119+
# rubocop:disable RSpec/BeforeAfterAll
110120
c.before(:all) do
111-
data = YAML.load(default_hiera_config)
112-
data.keys.each do |key|
121+
data = YAML.safe_load(default_hiera_config)
122+
data.each_key do |key|
113123
next unless data[key].is_a?(Hash)
114124

115125
if data[key][:datadir] == 'stub'
@@ -123,25 +133,27 @@ def set_hieradata(hieradata)
123133
f.write data.to_yaml
124134
end
125135
end
136+
# rubocop:enable RSpec/BeforeAfterAll
126137

127138
c.before(:each) do
128139
@spec_global_env_temp = Dir.mktmpdir('simpspec')
129140

130141
if defined?(environment)
131142
set_environment(environment)
132-
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))
133144
end
134145

135146
# ensure the user running these tests has an accessible environmentpath
147+
Puppet[:digest_algorithm] = 'sha256'
136148
Puppet[:environmentpath] = @spec_global_env_temp
137149
Puppet[:user] = Etc.getpwuid(Process.uid).name
138150
Puppet[:group] = Etc.getgrgid(Process.gid).name
139151

140152
# sanitize hieradata
141153
if defined?(hieradata)
142-
set_hieradata(hieradata.gsub(':','_'))
154+
set_hieradata(hieradata.gsub(':', '_'))
143155
elsif defined?(class_name)
144-
set_hieradata(class_name.gsub(':','_'))
156+
set_hieradata(class_name.gsub(':', '_'))
145157
end
146158
end
147159

@@ -150,34 +162,12 @@ def set_hieradata(hieradata)
150162
FileUtils.rm_rf(@spec_global_env_temp)
151163
@spec_global_env_temp = nil
152164
end
153-
154-
if ENV['RSPEC_TIME']
155-
c.before(:all) do
156-
@suite_start_time = Time.now
157-
end
158-
159-
c.before(:context) do
160-
@context_start_time = Time.now
161-
end
162-
163-
c.before(:example) do
164-
@example_start_time = Time.now
165-
end
166-
167-
c.after(:all) do
168-
puts("TIME FOR SUITE '#{self.class.description}': #{Time.now - @suite_start_time}")
169-
end
170-
171-
c.after(:context) do
172-
puts("TIME FOR CONTEXT '#{self.class.description}': #{Time.now - @context_start_time}")
173-
end
174-
end
175165
end
176166

177167
Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir|
178168
begin
179169
Pathname.new(dir).realpath
180-
rescue
181-
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."
182172
end
183173
end

0 commit comments

Comments
 (0)