Skip to content

Commit 2c7f378

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 2c7f378

File tree

2 files changed

+38
-52
lines changed

2 files changed

+38
-52
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: 36 additions & 50 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,17 @@
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:
21-
- name: SIMP Compliance Engine
22-
lookup_key: compliance_markup::enforcement
2330
- name: Custom Test Hiera
2431
path: "%{custom_hiera}.yaml"
2532
- name: "%{module_name}"
@@ -29,7 +36,7 @@
2936
defaults:
3037
data_hash: yaml_data
3138
datadir: "stub"
32-
EOM
39+
HIERA_CONFIG
3340

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

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

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

7885
RSpec.configure do |c|
7986
# If nothing else...
8087
c.default_facts = {
81-
:production => {
88+
production: {
8289
#:fqdn => 'production.rspec.test.localdomain',
83-
:path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
84-
:concat_basedir => '/tmp'
90+
path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
91+
concat_basedir: '/tmp'
8592
}
8693
}
8794

88-
c.trusted_server_facts = true if c.respond_to?(:trusted_server_facts)
89-
9095
c.mock_framework = :rspec
91-
c.mock_with :mocha
96+
c.mock_with :rspec
9297

9398
c.module_path = File.join(fixture_path, 'modules')
9499
c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir)
95100

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

98103
# Useless backtrace noise
99104
backtrace_exclusion_patterns = [
100-
/spec_helper/,
101-
/gems/
105+
%r{spec_helper},
106+
%r{gems},
102107
]
103108

104109
if c.respond_to?(:backtrace_exclusion_patterns)
@@ -107,9 +112,10 @@ def set_hieradata(hieradata)
107112
c.backtrace_clean_patterns = backtrace_exclusion_patterns
108113
end
109114

115+
# rubocop:disable RSpec/BeforeAfterAll
110116
c.before(:all) do
111-
data = YAML.load(default_hiera_config)
112-
data.keys.each do |key|
117+
data = YAML.safe_load(default_hiera_config)
118+
data.each_key do |key|
113119
next unless data[key].is_a?(Hash)
114120

115121
if data[key][:datadir] == 'stub'
@@ -123,25 +129,27 @@ def set_hieradata(hieradata)
123129
f.write data.to_yaml
124130
end
125131
end
132+
# rubocop:enable RSpec/BeforeAfterAll
126133

127134
c.before(:each) do
128135
@spec_global_env_temp = Dir.mktmpdir('simpspec')
129136

130137
if defined?(environment)
131138
set_environment(environment)
132-
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))
133140
end
134141

135142
# ensure the user running these tests has an accessible environmentpath
143+
Puppet[:digest_algorithm] = 'sha256'
136144
Puppet[:environmentpath] = @spec_global_env_temp
137145
Puppet[:user] = Etc.getpwuid(Process.uid).name
138146
Puppet[:group] = Etc.getgrgid(Process.gid).name
139147

140148
# sanitize hieradata
141149
if defined?(hieradata)
142-
set_hieradata(hieradata.gsub(':','_'))
150+
set_hieradata(hieradata.gsub(':', '_'))
143151
elsif defined?(class_name)
144-
set_hieradata(class_name.gsub(':','_'))
152+
set_hieradata(class_name.gsub(':', '_'))
145153
end
146154
end
147155

@@ -150,34 +158,12 @@ def set_hieradata(hieradata)
150158
FileUtils.rm_rf(@spec_global_env_temp)
151159
@spec_global_env_temp = nil
152160
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
175161
end
176162

177163
Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir|
178164
begin
179165
Pathname.new(dir).realpath
180-
rescue
181-
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."
182168
end
183169
end

0 commit comments

Comments
 (0)