mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 15:37:50 -08:00
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>
76 lines
1.4 KiB
Go
76 lines
1.4 KiB
Go
package lockfile
|
|
|
|
import (
|
|
"os"
|
|
"sort"
|
|
"testing"
|
|
|
|
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParser_Parse(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
inputFile string
|
|
want []ftypes.Package
|
|
}{
|
|
{
|
|
name: "happy path",
|
|
inputFile: "testdata/happy.lockfile",
|
|
want: []ftypes.Package{
|
|
{
|
|
ID: "cglib:cglib-nodep:2.1.2",
|
|
Name: "cglib:cglib-nodep",
|
|
Version: "2.1.2",
|
|
Locations: []ftypes.Location{
|
|
{
|
|
StartLine: 4,
|
|
EndLine: 4,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
ID: "org.springframework:spring-asm:3.1.3.RELEASE",
|
|
Name: "org.springframework:spring-asm",
|
|
Version: "3.1.3.RELEASE",
|
|
Locations: []ftypes.Location{
|
|
{
|
|
StartLine: 5,
|
|
EndLine: 5,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
ID: "org.springframework:spring-beans:5.0.5.RELEASE",
|
|
Name: "org.springframework:spring-beans",
|
|
Version: "5.0.5.RELEASE",
|
|
Locations: []ftypes.Location{
|
|
{
|
|
StartLine: 6,
|
|
EndLine: 6,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "empty",
|
|
inputFile: "testdata/empty.lockfile",
|
|
want: nil,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
parser := NewParser()
|
|
f, err := os.Open(tt.inputFile)
|
|
assert.NoError(t, err)
|
|
|
|
pkgs, _, _ := parser.Parse(f)
|
|
sort.Sort(ftypes.Packages(pkgs))
|
|
assert.Equal(t, tt.want, pkgs)
|
|
})
|
|
}
|
|
}
|