|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../../spec_helper' |
| 4 | +require OctocatalogDiff::Spec.require_path('/catalog') |
| 5 | +require OctocatalogDiff::Spec.require_path('/catalog-diff/filter/compilation_dir') |
| 6 | +require OctocatalogDiff::Spec.require_path('/cli/diffs') |
| 7 | + |
| 8 | +describe OctocatalogDiff::CatalogDiff::Filter::CompilationDir do |
| 9 | + before(:all) do |
| 10 | + @cat_compilation_dir_1 = OctocatalogDiff::Catalog.new( |
| 11 | + node: 'my.rspec.node', |
| 12 | + basedir: '/path/to/catalog1', |
| 13 | + json: File.read(OctocatalogDiff::Spec.fixture_path('catalogs/compilation-dir-1.json')) |
| 14 | + ) |
| 15 | + @cat_compilation_dir_2 = OctocatalogDiff::Catalog.new( |
| 16 | + node: 'my.rspec.node', |
| 17 | + basedir: '/path/to/catalog2', |
| 18 | + json: File.read(OctocatalogDiff::Spec.fixture_path('catalogs/compilation-dir-2.json')) |
| 19 | + ) |
| 20 | + end |
| 21 | + |
| 22 | + before(:each) do |
| 23 | + @logger, @logger_str = OctocatalogDiff::Spec.setup_logger |
| 24 | + end |
| 25 | + |
| 26 | + it 'should remove +/- full title changes due to compilation dirs' do |
| 27 | + opts = { |
| 28 | + ignore: [ |
| 29 | + { type: 'Varies_Due_To_Compilation_Dir_2' }, |
| 30 | + { type: 'Varies_Due_To_Compilation_Dir_3' }, |
| 31 | + { type: 'Varies_Due_To_Compilation_Dir_4' } |
| 32 | + ] |
| 33 | + } |
| 34 | + testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger) |
| 35 | + result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2) |
| 36 | + expect(result).to eq([]) |
| 37 | + expect(@logger_str.string).to match(%r{Varies_Due_To_Compilation_Dir_1\[/path/to/catalog2\] .*Suppressed}) |
| 38 | + expect(@logger_str.string).to match(%r{Varies_Due_To_Compilation_Dir_1\[/path/to/catalog1\] .*Suppressed}) |
| 39 | + end |
| 40 | + |
| 41 | + it 'should remove +/- partial title changes due to compilation dirs' do |
| 42 | + opts = { ignore: |
| 43 | + [ |
| 44 | + { type: 'Varies_Due_To_Compilation_Dir_1' }, |
| 45 | + { type: 'Varies_Due_To_Compilation_Dir_3' }, |
| 46 | + { type: 'Varies_Due_To_Compilation_Dir_4' } |
| 47 | + ] } |
| 48 | + testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger) |
| 49 | + result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2) |
| 50 | + expect(result).to eq([]) |
| 51 | + r1 = %r{Varies_Due_To_Compilation_Dir_2\[/aldsfjalkfjalksfd/path/to/catalog2/dflkjasfkljasdf\].*Suppressed} |
| 52 | + expect(@logger_str.string).to match(r1) |
| 53 | + r2 = %r{Varies_Due_To_Compilation_Dir_2\[/aldsfjalkfjalksfd/path/to/catalog1/dflkjasfkljasdf\].*Suppressed} |
| 54 | + expect(@logger_str.string).to match(r2) |
| 55 | + end |
| 56 | + |
| 57 | + it 'should remove ~ changes due to compilation dirs' do |
| 58 | + opts = { ignore: |
| 59 | + [ |
| 60 | + { type: 'Varies_Due_To_Compilation_Dir_1' }, |
| 61 | + { type: 'Varies_Due_To_Compilation_Dir_2' }, |
| 62 | + { type: 'Varies_Due_To_Compilation_Dir_4' }, |
| 63 | + { attr: "parameters\fdir_in_first_cat" }, |
| 64 | + { attr: "parameters\fdir_in_second_cat" } |
| 65 | + ] } |
| 66 | + testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger) |
| 67 | + result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2) |
| 68 | + expect(result).to eq([]) |
| 69 | + expect(@logger_str.string).to match(/WARN -- : Resource key.*parameters => dir .*Suppressed/) |
| 70 | + expect(@logger_str.string).to match(/WARN -- : Resource key.*parameters => dir_in_middle .*Suppressed/) |
| 71 | + end |
| 72 | + |
| 73 | + it 'should warn but not remove non-matching ! changes due to compilation dirs' do |
| 74 | + opts = { ignore: |
| 75 | + [ |
| 76 | + { type: 'Varies_Due_To_Compilation_Dir_1' }, |
| 77 | + { type: 'Varies_Due_To_Compilation_Dir_2' }, |
| 78 | + { type: 'Varies_Due_To_Compilation_Dir_4' }, |
| 79 | + { attr: "parameters\fdir" }, |
| 80 | + { attr: "parameters\fdir_in_middle" } |
| 81 | + ] } |
| 82 | + testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger) |
| 83 | + result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2) |
| 84 | + expect(result.size).to eq(2) |
| 85 | + common_str = "Varies_Due_To_Compilation_Dir_3\fCommon Title\fparameters\f" |
| 86 | + expect(result[0][1]).to eq("#{common_str}dir_in_first_cat") |
| 87 | + expect(result[1][1]).to eq("#{common_str}dir_in_second_cat") |
| 88 | + expect(@logger_str.string).to match(/WARN.+Varies_Due_To_Compilation_Dir_3\[Common Title\] parameters => dir.*verify/) |
| 89 | + end |
| 90 | + |
| 91 | + it 'should warn but not remove non-matching ~ changes due to compilation dirs' do |
| 92 | + opts = { ignore: |
| 93 | + [ |
| 94 | + { type: 'Varies_Due_To_Compilation_Dir_1' }, |
| 95 | + { type: 'Varies_Due_To_Compilation_Dir_2' }, |
| 96 | + { type: 'Varies_Due_To_Compilation_Dir_3' } |
| 97 | + ] } |
| 98 | + testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger) |
| 99 | + result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2) |
| 100 | + answer = [[ |
| 101 | + '~', |
| 102 | + "Varies_Due_To_Compilation_Dir_4\fCommon Title\fparameters\fdir", |
| 103 | + '/path/to/catalog1/onetime', |
| 104 | + '/path/to/catalog2/twotimes', |
| 105 | + { 'file' => nil, 'line' => nil }, |
| 106 | + { 'file' => nil, 'line' => nil } |
| 107 | + ]] |
| 108 | + expect(result).to eq(answer) |
| 109 | + expect(@logger_str.string).to match(/WARN -- : Resource key Varies_Due_To_Compilation_Dir_4.*please verify/) |
| 110 | + end |
| 111 | +end |
0 commit comments