mirror of
https://github.com/aquasecurity/trivy.git
synced 2026-02-13 04:03:21 +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:
@@ -4,19 +4,18 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"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
|
||||
want []ftypes.Package
|
||||
}{
|
||||
{
|
||||
file: "testdata/Pipfile_normal.lock",
|
||||
@@ -40,21 +39,8 @@ func TestParse(t *testing.T) {
|
||||
got, _, 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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user