mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 07:29:00 -08:00
refactor: unify Library and Package structs (#6633)
Signed-off-by: knqyf263 <knqyf263@gmail.com> Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com> Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
This commit is contained in:
@@ -10,14 +10,14 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/types"
|
||||
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
vectors := []struct {
|
||||
file string // Test input file
|
||||
want []types.Library
|
||||
wantDeps []types.Dependency
|
||||
want []ftypes.Package
|
||||
wantDeps []ftypes.Dependency
|
||||
}{
|
||||
{
|
||||
file: "testdata/packages_lock_simple.json",
|
||||
@@ -49,21 +49,8 @@ func TestParse(t *testing.T) {
|
||||
got, deps, err := NewParser().Parse(f)
|
||||
require.NoError(t, err)
|
||||
|
||||
sort.Slice(got, func(i, j int) bool {
|
||||
ret := strings.Compare(got[i].Name, got[j].Name)
|
||||
if ret == 0 {
|
||||
return got[i].Version < got[j].Version
|
||||
}
|
||||
return ret < 0
|
||||
})
|
||||
|
||||
sort.Slice(v.want, func(i, j int) bool {
|
||||
ret := strings.Compare(v.want[i].Name, v.want[j].Name)
|
||||
if ret == 0 {
|
||||
return v.want[i].Version < v.want[j].Version
|
||||
}
|
||||
return ret < 0
|
||||
})
|
||||
sort.Sort(ftypes.Packages(got))
|
||||
sort.Sort(ftypes.Packages(v.want))
|
||||
|
||||
assert.Equal(t, v.want, got)
|
||||
|
||||
@@ -76,7 +63,7 @@ func TestParse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func sortDeps(deps []types.Dependency) {
|
||||
func sortDeps(deps []ftypes.Dependency) {
|
||||
sort.Slice(deps, func(i, j int) bool {
|
||||
return strings.Compare(deps[i].ID, deps[j].ID) < 0
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user