|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../../spec_helper' |
| 4 | +require OctocatalogDiff::Spec.require_path('/api/v1/diff') |
| 5 | +require OctocatalogDiff::Spec.require_path('/catalog-diff/filter/json') |
| 6 | + |
| 7 | +describe OctocatalogDiff::CatalogDiff::Filter::JSON do |
| 8 | + let(:subject) { described_class.new } |
| 9 | + |
| 10 | + describe '#filtered?' do |
| 11 | + let(:str1a) { '{"foo":"bar"}' } |
| 12 | + let(:str1b) { "{\n \"foo\": \"bar\"\n}\n" } |
| 13 | + let(:str2) { '{"foo":"baz"}' } |
| 14 | + |
| 15 | + it 'should not filter out an added resource' do |
| 16 | + diff = ['+', "File\ffoobar.json", { 'parameters' => { 'content' => str1a } }] |
| 17 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 18 | + result = subject.filtered?(diff_obj) |
| 19 | + expect(result).to eq(false) |
| 20 | + end |
| 21 | + |
| 22 | + it 'should not filter out a removed resource' do |
| 23 | + diff = ['-', "File\ffoobar.json", { 'parameters' => { 'content' => str1a } }] |
| 24 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 25 | + result = subject.filtered?(diff_obj) |
| 26 | + expect(result).to eq(false) |
| 27 | + end |
| 28 | + |
| 29 | + it 'should not filter out a non-file resource' do |
| 30 | + diff = ['~', "Exec\ffoobar.json\fparameters\fcontent", str1a, str1b] |
| 31 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 32 | + result = subject.filtered?(diff_obj) |
| 33 | + expect(result).to eq(false) |
| 34 | + end |
| 35 | + |
| 36 | + it 'should not filter out a file whose extension is not .json' do |
| 37 | + diff = ['~', "File\ffoobar.txt\fparameters\fcontent", str1a, str1b] |
| 38 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 39 | + result = subject.filtered?(diff_obj) |
| 40 | + expect(result).to eq(false) |
| 41 | + end |
| 42 | + |
| 43 | + it 'should not filter out a change with no content change' do |
| 44 | + diff = ['~', "File\ffoobar.json\fparameters\fowner", 'root', 'nobody'] |
| 45 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 46 | + result = subject.filtered?(diff_obj) |
| 47 | + expect(result).to eq(false) |
| 48 | + end |
| 49 | + |
| 50 | + it 'should not filter out a change where JSON objects are dissimilar' do |
| 51 | + diff = ['~', "File\ffoobar.json\fparameters\fcontent", str1a, str2] |
| 52 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 53 | + result = subject.filtered?(diff_obj) |
| 54 | + expect(result).to eq(false) |
| 55 | + end |
| 56 | + |
| 57 | + it 'should not filter out a change where JSON is invalid' do |
| 58 | + x_str = '---{ "blah": "foo" }' |
| 59 | + diff = ['~', "File\ffoobar.json\fparameters\fcontent", x_str, x_str] |
| 60 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 61 | + result = subject.filtered?(diff_obj) |
| 62 | + expect(result).to eq(false) |
| 63 | + end |
| 64 | + |
| 65 | + it 'should not filter out a change where JSON is unparseable' do |
| 66 | + x_str = "--- !ruby/object:This::Does::Not::Exist\n foo: bar" |
| 67 | + diff = ['~', "File\ffoobar.json\fparameters\fcontent", x_str, x_str] |
| 68 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 69 | + result = subject.filtered?(diff_obj) |
| 70 | + expect(result).to eq(false) |
| 71 | + end |
| 72 | + |
| 73 | + it 'should filter out a whitespace-only change to a .json file' do |
| 74 | + diff = ['~', "File\ffoobar.json\fparameters\fcontent", str1a, str1b] |
| 75 | + diff_obj = OctocatalogDiff::API::V1::Diff.new(diff) |
| 76 | + result = subject.filtered?(diff_obj) |
| 77 | + expect(result).to eq(true) |
| 78 | + end |
| 79 | + end |
| 80 | +end |
0 commit comments