Skip to content

Commit e281f56

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 e281f56

File tree

2 files changed

+58
-46
lines changed

2 files changed

+58
-46
lines changed

Diff for: .github/workflows/pr_tests.yml

+2-2
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}}

Diff for: spec/spec_helper.rb

+56-44
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,27 @@
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: Custom Test Hiera
31+
path: "%{custom_hiera}.yaml"
32+
- name: "%{module_name}"
33+
path: "%{module_name}.yaml"
34+
- name: Common
35+
path: default.yaml
36+
defaults:
37+
data_hash: yaml_data
38+
datadir: "stub"
39+
HIERA_CONFIG
3840

3941
# This can be used from inside your spec tests to set the testable environment.
4042
# You can use this to stub out an ENC.
@@ -47,7 +49,7 @@
4749
# end
4850
#
4951
def set_environment(environment = :production)
50-
RSpec.configure { |c| c.default_facts['environment'] = environment.to_s }
52+
RSpec.configure { |c| c.default_facts['environment'] = environment.to_s }
5153
end
5254

5355
# This can be used from inside your spec tests to load custom hieradata within
@@ -69,39 +71,39 @@ def set_environment(environment = :production)
6971
#
7072
# Note: Any colons (:) are replaced with underscores (_) in the class name.
7173
def set_hieradata(hieradata)
72-
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
74+
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
7375
end
7476

75-
if not File.directory?(File.join(fixture_path,'hieradata')) then
76-
FileUtils.mkdir_p(File.join(fixture_path,'hieradata'))
77+
unless File.directory?(File.join(fixture_path, 'hieradata'))
78+
FileUtils.mkdir_p(File.join(fixture_path, 'hieradata'))
7779
end
7880

79-
if not File.directory?(File.join(fixture_path,'modules',module_name)) then
80-
FileUtils.mkdir_p(File.join(fixture_path,'modules',module_name))
81+
unless File.directory?(File.join(fixture_path, 'modules', module_name))
82+
FileUtils.mkdir_p(File.join(fixture_path, 'modules', module_name))
8183
end
8284

8385
RSpec.configure do |c|
8486
# If nothing else...
8587
c.default_facts = {
86-
:production => {
88+
production: {
8789
#:fqdn => 'production.rspec.test.localdomain',
88-
:path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
89-
:concat_basedir => '/tmp'
90+
path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
91+
concat_basedir: '/tmp'
9092
}
9193
}
9294

9395
c.mock_framework = :rspec
94-
c.mock_with :mocha
96+
c.mock_with :rspec
9597

9698
c.module_path = File.join(fixture_path, 'modules')
9799
c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir)
98100

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

101103
# Useless backtrace noise
102104
backtrace_exclusion_patterns = [
103-
/spec_helper/,
104-
/gems/
105+
%r{spec_helper},
106+
%r{gems},
105107
]
106108

107109
if c.respond_to?(:backtrace_exclusion_patterns)
@@ -110,21 +112,31 @@ def set_hieradata(hieradata)
110112
c.backtrace_clean_patterns = backtrace_exclusion_patterns
111113
end
112114

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

117128
File.open(c.hiera_config, 'w') do |f|
118129
f.write data.to_yaml
119130
end
120131
end
132+
# rubocop:enable RSpec/BeforeAfterAll
121133

122134
c.before(:each) do
123135
@spec_global_env_temp = Dir.mktmpdir('simpspec')
124136

125137
if defined?(environment)
126138
set_environment(environment)
127-
FileUtils.mkdir_p(File.join(@spec_global_env_temp,environment.to_s))
139+
FileUtils.mkdir_p(File.join(@spec_global_env_temp, environment.to_s))
128140
end
129141

130142
# ensure the user running these tests has an accessible environmentpath
@@ -135,9 +147,9 @@ def set_hieradata(hieradata)
135147

136148
# sanitize hieradata
137149
if defined?(hieradata)
138-
set_hieradata(hieradata.gsub(':','_'))
150+
set_hieradata(hieradata.gsub(':', '_'))
139151
elsif defined?(class_name)
140-
set_hieradata(class_name.gsub(':','_'))
152+
set_hieradata(class_name.gsub(':', '_'))
141153
end
142154
end
143155

@@ -151,7 +163,7 @@ def set_hieradata(hieradata)
151163
Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir|
152164
begin
153165
Pathname.new(dir).realpath
154-
rescue
155-
fail "ERROR: The module '#{dir}' is not installed. Tests cannot continue."
166+
rescue StandardError
167+
raise "ERROR: The module '#{dir}' is not installed. Tests cannot continue."
156168
end
157169
end

0 commit comments

Comments
 (0)