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