mirror of
https://github.com/anchore/syft
synced 2024-11-10 06:14:16 +00:00
048df17e3d
* use pkg values in relationship fields Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add linter rule for using values in relationships Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * use new cmptest package for comparing relationships Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * create cmptest for common cmp.Diff options in test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * condense matches for relationship ruleguard Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * remove relationship type from rules Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * restore build tag Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * suggest using values Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * nil check pkgs Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
29 lines
583 B
Go
29 lines
583 B
Go
package cmptest
|
|
|
|
import (
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/anchore/syft/syft/file"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
)
|
|
|
|
type LicenseComparer func(x, y pkg.License) bool
|
|
|
|
func DefaultLicenseComparer(x, y pkg.License) bool {
|
|
return cmp.Equal(x, y, cmp.Comparer(DefaultLocationComparer), cmp.Comparer(
|
|
func(x, y file.LocationSet) bool {
|
|
xs := x.ToSlice()
|
|
ys := y.ToSlice()
|
|
if len(xs) != len(ys) {
|
|
return false
|
|
}
|
|
for i, xe := range xs {
|
|
ye := ys[i]
|
|
if !DefaultLocationComparer(xe, ye) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
},
|
|
))
|
|
}
|