Skip to content

Commit

Permalink
change method of relationship sort to simple string dump
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman committed Sep 20, 2023
1 parent 6ade370 commit 89846cd
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 1,944 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ require (
modernc.org/sqlite v1.25.0
)

require github.com/sanity-io/litter v1.5.5

require (
dario.cat/mergo v1.0.0 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect
Expand Down Expand Up @@ -176,7 +178,6 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sanity-io/litter v1.5.5 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
Expand Down
73 changes: 14 additions & 59 deletions syft/pkg/cataloger/internal/pkgtest/test_generic_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sanity-io/litter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -252,43 +253,21 @@ func (p *CatalogTester) TestCataloger(t *testing.T, cataloger pkg.Cataloger) {
}
}

//func relationshipLess(x, y artifact.Relationship) bool {
// xFromPkg, ok := x.From.(pkg.Package)
// if !ok {
// return relationshipLessByID(x, y)
// }
// yFromPkg, ok := y.From.(pkg.Package)
// if !ok {
// return relationshipLessByID(x, y)
// }
//
//
//
// //xFrom := x.From.ID()
// //yFrom := y.From.ID()
// //if xFrom == yFrom {
// // xTo := x.To.ID()
// // yTo := y.To.ID()
// // if xTo == yTo {
// // return x.Type < y.Type
// // }
// // return xTo < yTo
// //}
// //return xFrom < yFrom
//}
var relationshipStringer = litter.Options{
Compact: true,
StripPackageNames: false,
HidePrivateFields: true, // we want to ignore package IDs
HideZeroValues: true,
StrictGo: true,
//FieldExclusions: ... // these can be added for future values that need to be ignored
//FieldFilter: ...
}

func relationshipLess(x, y artifact.Relationship) bool {
xFrom := x.From.ID()
yFrom := y.From.ID()
if xFrom == yFrom {
xTo := x.To.ID()
yTo := y.To.ID()
if xTo == yTo {
return x.Type < y.Type
}
return xTo < yTo
}
return xFrom < yFrom
// we just need a stable sort, the ordering does not need to be sensible
xStr := relationshipStringer.Sdump(x)
yStr := relationshipStringer.Sdump(y)
return xStr < yStr
}

// nolint:funlen
Expand Down Expand Up @@ -343,30 +322,6 @@ func (p *CatalogTester) assertPkgs(t *testing.T, pkgs []pkg.Package, relationshi
),
)

//for _, pp := range pkgs {
// switch pp.Name {
// case "alpine-baselayout", "alpine-baselayout-data", "alpine-tools", "alpine-keys", "apk-tools", "busybox", "ca-certificates-bundle":
// continue
// }
// fmt.Println()
// fmt.Println(pp.Name, pp.Version, pp.FoundBy)
// fmt.Println()
//
// fmt.Println("MetadataType: pkg.ApkMetadataType,")
// fmt.Printf("Metadata: ")
// sq := litter.Options{
// HidePrivateFields: true,
// HideZeroValues: true,
// StrictGo: true,
// DisablePointerReplacement: true,
// }
// sq.Dump(pp.Metadata)
// fmt.Println()
// fmt.Println("############################################################################")
// fmt.Println("############################################################################")
// fmt.Println("############################################################################")
//}

{
var r diffReporter
var opts []cmp.Option
Expand Down
Loading

0 comments on commit 89846cd

Please sign in to comment.