Skip to content

Commit 3accf4c

Browse files
author
Kevin Paulisse
committed
Add integration test demonstrating #70
1 parent 3840851 commit 3accf4c

3 files changed

Lines changed: 120 additions & 2 deletions

File tree

lib/octocatalog-diff/catalog-diff/display/text.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,9 @@ def self.adjust_for_display_datatype_changes(diff, option, logger = nil)
395395
else
396396
# Adjust the display and return modified object
397397
msg = "Adjust display for #{diff_obj[1].gsub(/\f/, '::')}: " \
398-
"#{diff_obj[2].inspect} -> #{x2}; "\
399-
"#{diff_obj[3].inspect} -> #{x3}"
398+
"old=#{x2.inspect} new=#{x3.inspect} "\
399+
"(extra debugging: #{diff_obj[2].inspect} -> #{x2}; "\
400+
"#{diff_obj[3].inspect} -> #{x3})"
400401
logger.debug(msg) if logger
401402
diff_obj[2] = x2
402403
diff_obj[3] = x3
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
[
3+
"+",
4+
"File\f/tmp/foo",
5+
{
6+
"type": "File",
7+
"title": "/tmp/new-file/ignored/one",
8+
"exported": false,
9+
"parameters": {
10+
"content": "new repo",
11+
"tag": "ignored_catalog_diff"
12+
}
13+
},
14+
{
15+
"file": "/var/folders/dw/xxx/T/yyy/environments/production/modules/mymodule/manifests/resource2.pp",
16+
"line": 17
17+
}
18+
],
19+
[
20+
"~",
21+
"File\f/tmp/bar\fparameters\fmode",
22+
755,
23+
"755",
24+
{
25+
"file": "/var/folders/dw/xxx/T/yyy/environments/production/modules/mymodule/manifests/resource2.pp",
26+
"line": 27
27+
},
28+
{
29+
"file": "/var/folders/dw/xxx/T/yyy/environments/production/modules/mymodule/manifests/resource2.pp",
30+
"line": 27
31+
}
32+
]
33+
]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'integration_helper'
4+
5+
require 'json'
6+
7+
require OctocatalogDiff::Spec.require_path('/api/v1')
8+
require OctocatalogDiff::Spec.require_path('/cli/printer')
9+
10+
describe 'datatype display integration' do
11+
let(:diff_array_1) { JSON.parse(OctocatalogDiff::Spec.fixture_read('diffs/datatype-differences.json')) }
12+
let(:diff_array_2) { JSON.parse(OctocatalogDiff::Spec.fixture_read('diffs/ignore-tags-reversed.json')) }
13+
14+
before(:each) do
15+
@logger, @logger_str = OctocatalogDiff::Spec.setup_logger
16+
@stdout_cache = $stdout
17+
@stderr_cache = $stderr
18+
$stdout = StringIO.new
19+
$stderr = StringIO.new
20+
end
21+
22+
after(:each) do
23+
$stdout = @stdout_cache
24+
$stderr = @stderr_cache
25+
end
26+
27+
context 'display enabled' do
28+
let(:options) { { display_datatype_changes: true, format: :text } }
29+
context 'with datatype changes' do
30+
it 'should display proper differences and debug messages' do
31+
subject = OctocatalogDiff::Cli::Printer.new(options, @logger)
32+
subject.printer(diff_array_1)
33+
expect($stderr.string).to eq('')
34+
stdout = $stdout.string.split(/\n/).map(&:strip)
35+
expect(stdout).to include('File[/tmp/bar] =>')
36+
expect(stdout).to include('- 755')
37+
expect(stdout).to include('+ "755"')
38+
r = Regexp.escape('Adjust display for File::/tmp/bar::parameters::mode: old=755 new="\"755\""')
39+
expect(@logger_str.string).to match(Regexp.new(r))
40+
end
41+
end
42+
43+
context 'with no datatype changes' do
44+
it 'should display proper differences and debug messages' do
45+
subject = OctocatalogDiff::Cli::Printer.new(options, @logger)
46+
subject.printer(diff_array_2)
47+
expect($stderr.string).to eq('')
48+
stdout = $stdout.string.split(/\n/).map(&:strip)
49+
expect(stdout).to include('Mymodule::Resource2[three] =>')
50+
expect(stdout).to include('- BAR-NEW')
51+
expect(stdout).to include('+ BAR-OLD')
52+
expect(@logger_str.string).not_to match(/Adjust display for/)
53+
end
54+
end
55+
end
56+
57+
context 'display disabled' do
58+
let(:options) { { display_datatype_changes: false, format: :text } }
59+
context 'with datatype changes' do
60+
it 'should display proper differences and debug messages' do
61+
subject = OctocatalogDiff::Cli::Printer.new(options, @logger)
62+
subject.printer(diff_array_1)
63+
expect($stderr.string).to eq('')
64+
stdout = $stdout.string.split(/\n/).map(&:strip)
65+
expect(stdout).to include('+ File[/tmp/foo]')
66+
expect(stdout).not_to include('File[/tmp/bar] =>')
67+
expect(@logger_str.string).to match(%r{Adjust display for File::/tmp/bar::parameters::mode: 755 != "755" DELETED})
68+
end
69+
end
70+
71+
context 'with no datatype changes' do
72+
it 'should display proper differences and debug messages' do
73+
subject = OctocatalogDiff::Cli::Printer.new(options, @logger)
74+
subject.printer(diff_array_2)
75+
expect($stderr.string).to eq('')
76+
stdout = $stdout.string.split(/\n/).map(&:strip)
77+
expect(stdout).to include('Mymodule::Resource2[three] =>')
78+
expect(stdout).to include('- BAR-NEW')
79+
expect(stdout).to include('+ BAR-OLD')
80+
expect(@logger_str.string).not_to match(/Adjust display for/)
81+
end
82+
end
83+
end
84+
end

0 commit comments

Comments
 (0)