Skip to content

Commit caebbd9

Browse files
authored
[puppetsync] Don't ignore Puppet 8 failures (#55)
1 parent dce18ca commit caebbd9

File tree

2 files changed

+57
-36
lines changed

2 files changed

+57
-36
lines changed

.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}}

spec/spec_helper.rb

+55-34
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,26 +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__,'../..')))
19+
module_name = File.basename(File.expand_path(File.join(__FILE__, '../..')))
1120

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

19-
default_hiera_config =<<-EOM
26+
default_hiera_config = <<~HIERA_CONFIG
2027
---
21-
:backends:
22-
- "yaml"
23-
:yaml:
24-
:datadir: "stub"
25-
:hierarchy:
26-
- "%{custom_hiera}"
27-
- "%{module_name}"
28-
- "default"
29-
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
3040

3141
# This can be used from inside your spec tests to set the testable environment.
3242
# You can use this to stub out an ENC.
@@ -64,36 +74,36 @@ def set_hieradata(hieradata)
6474
RSpec.configure { |c| c.default_facts['custom_hiera'] = hieradata }
6575
end
6676

67-
if not File.directory?(File.join(fixture_path,'hieradata')) then
68-
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'))
6979
end
7080

71-
if not File.directory?(File.join(fixture_path,'modules',module_name)) then
72-
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))
7383
end
7484

7585
RSpec.configure do |c|
7686
# If nothing else...
7787
c.default_facts = {
78-
:production => {
88+
production: {
7989
#:fqdn => 'production.rspec.test.localdomain',
80-
:path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
81-
:concat_basedir => '/tmp'
90+
path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
91+
concat_basedir: '/tmp'
8292
}
8393
}
8494

8595
c.mock_framework = :rspec
86-
c.mock_with :mocha
96+
c.mock_with :rspec
8797

8898
c.module_path = File.join(fixture_path, 'modules')
8999
c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir)
90100

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

93103
# Useless backtrace noise
94104
backtrace_exclusion_patterns = [
95-
/spec_helper/,
96-
/gems/
105+
%r{spec_helper},
106+
%r{gems},
97107
]
98108

99109
if c.respond_to?(:backtrace_exclusion_patterns)
@@ -102,33 +112,44 @@ def set_hieradata(hieradata)
102112
c.backtrace_clean_patterns = backtrace_exclusion_patterns
103113
end
104114

115+
# rubocop:disable RSpec/BeforeAfterAll
105116
c.before(:all) do
106-
data = YAML.load(default_hiera_config)
107-
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
108127

109128
File.open(c.hiera_config, 'w') do |f|
110129
f.write data.to_yaml
111130
end
112131
end
132+
# rubocop:enable RSpec/BeforeAfterAll
113133

114134
c.before(:each) do
115135
@spec_global_env_temp = Dir.mktmpdir('simpspec')
116136

117137
if defined?(environment)
118138
set_environment(environment)
119-
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))
120140
end
121141

122142
# ensure the user running these tests has an accessible environmentpath
143+
Puppet[:digest_algorithm] = 'sha256'
123144
Puppet[:environmentpath] = @spec_global_env_temp
124145
Puppet[:user] = Etc.getpwuid(Process.uid).name
125146
Puppet[:group] = Etc.getgrgid(Process.gid).name
126147

127148
# sanitize hieradata
128149
if defined?(hieradata)
129-
set_hieradata(hieradata.gsub(':','_'))
150+
set_hieradata(hieradata.gsub(':', '_'))
130151
elsif defined?(class_name)
131-
set_hieradata(class_name.gsub(':','_'))
152+
set_hieradata(class_name.gsub(':', '_'))
132153
end
133154
end
134155

@@ -142,7 +163,7 @@ def set_hieradata(hieradata)
142163
Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir|
143164
begin
144165
Pathname.new(dir).realpath
145-
rescue
146-
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."
147168
end
148169
end

0 commit comments

Comments
 (0)