mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 07:29:00 -08:00
refactor: rename scanner to service (#8584)
This commit is contained in:
73
pkg/scan/utils/utils_test.go
Normal file
73
pkg/scan/utils/utils_test.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func TestFormatSrcVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
pkg types.Package
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "happy path",
|
||||
pkg: types.Package{
|
||||
SrcVersion: "1.2.3",
|
||||
SrcRelease: "1",
|
||||
},
|
||||
want: "1.2.3-1",
|
||||
},
|
||||
{
|
||||
name: "with epoch",
|
||||
pkg: types.Package{
|
||||
SrcEpoch: 2,
|
||||
SrcVersion: "1.2.3",
|
||||
SrcRelease: "alpha",
|
||||
},
|
||||
want: "2:1.2.3-alpha",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := FormatSrcVersion(tt.pkg)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
pkg types.Package
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "happy path",
|
||||
pkg: types.Package{
|
||||
Version: "1.2.3",
|
||||
Release: "1",
|
||||
},
|
||||
want: "1.2.3-1",
|
||||
},
|
||||
{
|
||||
name: "with epoch",
|
||||
pkg: types.Package{
|
||||
Epoch: 2,
|
||||
Version: "1.2.3",
|
||||
Release: "alpha",
|
||||
},
|
||||
want: "2:1.2.3-alpha",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := FormatVersion(tt.pkg)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user