Skip to content

Commit 4c12d0f

Browse files
(SIMP-10433) simplib::inspect acceptance test fail Puppet7 (#262)
Fixed log normalization that caused the simplib::inspect acceptance test to fail with the latest Puppet 7 SIMP-10433 #close
1 parent 4db692d commit 4c12d0f

1 file changed

Lines changed: 34 additions & 50 deletions

File tree

spec/acceptance/suites/default/inspect_spec.rb

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,54 @@
22

33
test_name 'simplib::inspect function'
44

5-
def normalize(puppet_log, keep_warning_lines_only = false)
6-
# remove normal puppet log lines and inspect/simplib::inspect
7-
# 'puts' lines, as their ordering relative to the Puppet warning
8-
# lines is non-deterministic
9-
normalized_lines = puppet_log.split("\n").delete_if do |line|
10-
line.include?('unresolved dependencies') or
11-
line.include?('Loading facts') or
12-
line.include?('Compiled catalog for') or
13-
line.include?('Applying configuration version') or
14-
line.include?('Applied catalog in') or
15-
line.match(/^Inspect:/)
16-
end
17-
18-
if keep_warning_lines_only
19-
normalized_lines.delete_if { |line| !line.include?('Warning: ') }
20-
end
5+
describe 'simplib::inspect function' do
216

22-
normalized_log = normalized_lines.join("\n")
23-
# remove color formatting
24-
yellow_bold_fmt_begin = "\e[1;33m"
25-
fmt_clear = "\e[0m"
26-
bad_fmt = "\e[m" # used at the beginning of Notice lines
27-
normalized_log.gsub!(yellow_bold_fmt_begin, '')
28-
normalized_log.gsub!(fmt_clear, '')
29-
normalized_log.gsub!(bad_fmt, '')
30-
normalized_log + "\n"
31-
end
7+
# Only return simplib::inspect lines from the Puppet log minus any ANSI
8+
# escape sequences for formatting (e.g. color).
9+
#
10+
# NOTE: Have to remove ANSI formatting because beaker does not provide a
11+
# mechanism to enable the `--color=false` option on `puppet apply`.
12+
def normalize_inspect_lines(puppet_log)
13+
normalized_lines = puppet_log.gsub(/\e\[\d*(;\d+)*m/, "").split("\n").select do |line|
14+
line.match(/^Notice: .*Type =>/)
15+
end
3216

33-
describe 'simplib::inspect function' do
17+
normalized_lines.join("\n")
18+
end
3419

3520
hosts.each do |server|
3621
context "logs variables with simplib::inspect on #{server}" do
3722
let (:manifest) {
38-
<<-EOS
39-
$var1 = "var1 value"
40-
$var2 = true
41-
$var3 = { 'a' => 'b'}
42-
$var4 = undef
43-
44-
simplib::inspect('var1', 'oneline_json')
45-
simplib::inspect('var2', 'oneline_json')
46-
simplib::inspect('var3', 'oneline_json')
47-
simplib::inspect('var4', 'oneline_json')
23+
<<~EOS
24+
$var1 = "var1 value"
25+
$var2 = true
26+
$var3 = { 'a' => 'b'}
27+
$var4 = undef
28+
29+
simplib::inspect('var1', 'oneline_json')
30+
simplib::inspect('var2', 'oneline_json')
31+
simplib::inspect('var3', 'oneline_json')
32+
simplib::inspect('var4', 'oneline_json')
4833
EOS
4934
}
5035

5136
it 'should be log variables' do
5237
results = apply_manifest_on(server, manifest)
53-
5438
output = results.output
5539

5640
# this is ugly, but is logged twice
57-
expected = <<EOM
58-
Notice: Type => String Content => "var1 value"
59-
Notice: /Stage[main]/Main/Notify[DEBUG_INSPECT_var1]/message: defined 'message' as 'Type => String Content => "var1 value"'
60-
Notice: Type => TrueClass Content => true
61-
Notice: /Stage[main]/Main/Notify[DEBUG_INSPECT_var2]/message: defined 'message' as 'Type => TrueClass Content => true'
62-
Notice: Type => Hash Content => {"a":"b"}
63-
Notice: /Stage[main]/Main/Notify[DEBUG_INSPECT_var3]/message: defined 'message' as 'Type => Hash Content => {"a":"b"}'
64-
Notice: Type => NilClass Content => null
65-
Notice: /Stage[main]/Main/Notify[DEBUG_INSPECT_var4]/message: defined 'message' as 'Type => NilClass Content => null'
66-
EOM
67-
68-
expect(normalize(results.output)).to eq(expected)
41+
expected = <<~EOM
42+
Notice: Type => String Content => "var1 value"
43+
Notice: /Stage[main]/Main/Notify[DEBUG_INSPECT_var1]/message: defined 'message' as 'Type => String Content => "var1 value"'
44+
Notice: Type => TrueClass Content => true
45+
Notice: /Stage[main]/Main/Notify[DEBUG_INSPECT_var2]/message: defined 'message' as 'Type => TrueClass Content => true'
46+
Notice: Type => Hash Content => {"a":"b"}
47+
Notice: /Stage[main]/Main/Notify[DEBUG_INSPECT_var3]/message: defined 'message' as 'Type => Hash Content => {"a":"b"}'
48+
Notice: Type => NilClass Content => null
49+
Notice: /Stage[main]/Main/Notify[DEBUG_INSPECT_var4]/message: defined 'message' as 'Type => NilClass Content => null'
50+
EOM
51+
52+
expect(normalize_inspect_lines(results.output)).to eq(expected.chomp)
6953
end
7054
end
7155
end

0 commit comments

Comments
 (0)