github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/internal/cmptest/license.go (about)

     1  package cmptest
     2  
     3  import (
     4  	"github.com/google/go-cmp/cmp"
     5  
     6  	"github.com/anchore/syft/syft/file"
     7  	"github.com/anchore/syft/syft/pkg"
     8  )
     9  
    10  type LicenseComparer func(x, y pkg.License) bool
    11  
    12  func DefaultLicenseComparer(x, y pkg.License) bool {
    13  	return cmp.Equal(x, y, cmp.Comparer(DefaultLocationComparer), cmp.Comparer(
    14  		func(x, y file.LocationSet) bool {
    15  			xs := x.ToSlice()
    16  			ys := y.ToSlice()
    17  			if len(xs) != len(ys) {
    18  				return false
    19  			}
    20  			for i, xe := range xs {
    21  				ye := ys[i]
    22  				if !DefaultLocationComparer(xe, ye) {
    23  					return false
    24  				}
    25  			}
    26  			return true
    27  		},
    28  	))
    29  }