|
2 | 2 |
|
3 | 3 | test_name 'simplib::inspect function' |
4 | 4 |
|
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 |
21 | 6 |
|
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 |
32 | 16 |
|
33 | | -describe 'simplib::inspect function' do |
| 17 | + normalized_lines.join("\n") |
| 18 | + end |
34 | 19 |
|
35 | 20 | hosts.each do |server| |
36 | 21 | context "logs variables with simplib::inspect on #{server}" do |
37 | 22 | 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') |
48 | 33 | EOS |
49 | 34 | } |
50 | 35 |
|
51 | 36 | it 'should be log variables' do |
52 | 37 | results = apply_manifest_on(server, manifest) |
53 | | - |
54 | 38 | output = results.output |
55 | 39 |
|
56 | 40 | # 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) |
69 | 53 | end |
70 | 54 | end |
71 | 55 | end |
|
0 commit comments