github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/table/encoder_test.go (about)

     1  package table
     2  
     3  import (
     4  	"flag"
     5  	"testing"
     6  
     7  	"github.com/go-test/deep"
     8  	"github.com/nextlinux/gosbom/gosbom/formats/internal/testutils"
     9  )
    10  
    11  var updateTableGoldenFiles = flag.Bool("update-table", false, "update the *.golden files for table format")
    12  
    13  func TestTableEncoder(t *testing.T) {
    14  	testutils.AssertEncoderAgainstGoldenSnapshot(t,
    15  		Format(),
    16  		testutils.DirectoryInput(t),
    17  		*updateTableGoldenFiles,
    18  		false,
    19  	)
    20  }
    21  
    22  func TestRemoveDuplicateRows(t *testing.T) {
    23  	data := [][]string{
    24  		{"1", "2", "3"},
    25  		{"a", "b", "c"},
    26  		{"1", "2", "3"},
    27  		{"a", "b", "c"},
    28  		{"1", "2", "3"},
    29  		{"4", "5", "6"},
    30  		{"1", "2", "1"},
    31  	}
    32  
    33  	expected := [][]string{
    34  		{"1", "2", "3"},
    35  		{"a", "b", "c"},
    36  		{"4", "5", "6"},
    37  		{"1", "2", "1"},
    38  	}
    39  
    40  	actual := removeDuplicateRows(data)
    41  
    42  	if diffs := deep.Equal(expected, actual); len(diffs) > 0 {
    43  		t.Errorf("found diffs!")
    44  		for _, d := range diffs {
    45  			t.Errorf("   diff: %+v", d)
    46  		}
    47  	}
    48  
    49  }