github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/formats/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/formats/internal/testutils"
    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  	testutils.AssertEncoderAgainstGoldenSnapshot(t,
    16  		testutils.EncoderSnapshotTestConfig{
    17  			Subject:                     testutils.DirectoryInput(t, t.TempDir()),
    18  			Format:                      Format(),
    19  			UpdateSnapshot:              *updateSnapshot,
    20  			PersistRedactionsInSnapshot: true,
    21  			IsJSON:                      false,
    22  		},
    23  	)
    24  }
    25  
    26  func TestRemoveDuplicateRows(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"},
    39  		{"a", "b", "c"},
    40  		{"4", "5", "6"},
    41  		{"1", "2", "1"},
    42  	}
    43  
    44  	actual := removeDuplicateRows(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  }