mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
* fix: sorting locations should consider pkg evidence Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * simplify location test options for comparison Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package cmptest
|
|
|
|
import (
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
|
|
"github.com/anchore/syft/syft/file"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
)
|
|
|
|
func DefaultOptions() []cmp.Option {
|
|
return BuildOptions(nil, nil)
|
|
}
|
|
|
|
func DefaultIgnoreLocationLayerOptions() []cmp.Option {
|
|
return BuildOptions(LicenseComparerWithoutLocationLayer, LocationComparerWithoutLayer)
|
|
}
|
|
|
|
func BuildOptions(licenseCmp LicenseComparer, locationCmp LocationComparer) []cmp.Option {
|
|
if licenseCmp == nil {
|
|
licenseCmp = DefaultLicenseComparer
|
|
}
|
|
|
|
if locationCmp == nil {
|
|
locationCmp = DefaultLocationComparer
|
|
}
|
|
|
|
return []cmp.Option{
|
|
cmpopts.IgnoreFields(pkg.Package{}, "id"), // note: ID is not deterministic for test purposes
|
|
cmpopts.SortSlices(pkg.Less),
|
|
cmpopts.SortSlices(DefaultRelationshipComparer),
|
|
cmp.Comparer(buildSetComparer[file.Location, file.LocationSet](locationCmp)),
|
|
cmp.Comparer(buildSetComparer[pkg.License, pkg.LicenseSet](licenseCmp)),
|
|
cmp.Comparer(locationCmp),
|
|
cmp.Comparer(licenseCmp),
|
|
}
|
|
}
|