github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/format/table/encoder_test.go (about) 1 package table 2 3 import ( 4 "flag" 5 "testing" 6 7 "github.com/go-test/deep" 8 9 "github.com/anchore/syft/syft/format/internal/testutil" 10 ) 11 12 var updateSnapshot = flag.Bool("update-table", false, "update the *.golden files for table format") 13 14 func TestTableEncoder(t *testing.T) { 15 testutil.AssertEncoderAgainstGoldenSnapshot(t, 16 testutil.EncoderSnapshotTestConfig{ 17 Subject: testutil.DirectoryInput(t, t.TempDir()), 18 Format: NewFormatEncoder(), 19 UpdateSnapshot: *updateSnapshot, 20 PersistRedactionsInSnapshot: true, 21 IsJSON: false, 22 }, 23 ) 24 } 25 26 func Test_markDuplicateRows(t *testing.T) { 27 data := [][]string{ 28 {"1", "2", "3"}, 29 {"a", "b", "c"}, 30 {"1", "2", "3"}, 31 {"a", "b", "c"}, 32 {"1", "2", "3"}, 33 {"4", "5", "6"}, 34 {"1", "2", "1"}, 35 } 36 37 expected := [][]string{ 38 {"1", "2", "3", "(+2 duplicates)"}, 39 {"a", "b", "c", "(+1 duplicate)"}, 40 {"4", "5", "6", ""}, 41 {"1", "2", "1", ""}, 42 } 43 44 actual := markDuplicateRows(data) 45 46 if diffs := deep.Equal(expected, actual); len(diffs) > 0 { 47 t.Errorf("found diffs!") 48 for _, d := range diffs { 49 t.Errorf(" diff: %+v", d) 50 } 51 } 52 53 }