Skip to content

Commit

Permalink
Fix flaky test and use cmp instead of reflect.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 714905592
  • Loading branch information
erikvarga authored and copybara-github committed Jan 13, 2025
1 parent 8a06ed5 commit ed18178
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions extractor/filesystem/language/dotnet/depsjson/depsjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"io/fs"
"os"
"path/filepath"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -63,8 +62,8 @@ func TestNew(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := depsjson.New(tt.cfg)
if !reflect.DeepEqual(got.Config(), tt.wantCfg) {
t.Errorf("New(%+v).Config(): got %+v, want %+v", tt.cfg, got.Config(), tt.wantCfg)
if diff := cmp.Diff(tt.wantCfg, got.Config()); diff != "" {
t.Errorf("New(%+v).Config(): (-want +got):\n%s", tt.cfg, diff)
}
})
}
Expand Down Expand Up @@ -280,13 +279,17 @@ func TestExtract(t *testing.T) {

got, err := e.Extract(context.Background(), input)

if diff := cmp.Diff(tt.wantInventory, got); diff != "" {
if diff := cmp.Diff(tt.wantInventory, got, cmpopts.SortSlices(invLess)); diff != "" {
t.Errorf("Inventory mismatch (-want +got):\n%s", diff)
}
})
}
}

func invLess(i1, i2 *extractor.Inventory) bool {
return i1.Name < i2.Name
}

func TestToPURL(t *testing.T) {
e := depsjson.Extractor{}
i := &extractor.Inventory{
Expand Down

0 comments on commit ed18178

Please sign in to comment.