Files
syft/syft/format/table/encoder_test.go
T
Alex Goodman 6377465440 Mark duplicated rows in table output (#2679)
* mark duplicated rows in table output

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix unit test

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
2024-02-29 09:33:00 -05:00

54 lines
1.1 KiB
Go

package table
import (
"flag"
"testing"
"github.com/go-test/deep"
"github.com/anchore/syft/syft/format/internal/testutil"
)
var updateSnapshot = flag.Bool("update-table", false, "update the *.golden files for table format")
func TestTableEncoder(t *testing.T) {
testutil.AssertEncoderAgainstGoldenSnapshot(t,
testutil.EncoderSnapshotTestConfig{
Subject: testutil.DirectoryInput(t, t.TempDir()),
Format: NewFormatEncoder(),
UpdateSnapshot: *updateSnapshot,
PersistRedactionsInSnapshot: true,
IsJSON: false,
},
)
}
func Test_markDuplicateRows(t *testing.T) {
data := [][]string{
{"1", "2", "3"},
{"a", "b", "c"},
{"1", "2", "3"},
{"a", "b", "c"},
{"1", "2", "3"},
{"4", "5", "6"},
{"1", "2", "1"},
}
expected := [][]string{
{"1", "2", "3", "(+2 duplicates)"},
{"a", "b", "c", "(+1 duplicate)"},
{"4", "5", "6", ""},
{"1", "2", "1", ""},
}
actual := markDuplicateRows(data)
if diffs := deep.Equal(expected, actual); len(diffs) > 0 {
t.Errorf("found diffs!")
for _, d := range diffs {
t.Errorf(" diff: %+v", d)
}
}
}