refactor: rename scanner to service (#8584)

This commit is contained in:
Teppei Fukuda
2025-03-24 03:47:03 +04:00
committed by GitHub
parent de7eb13938
commit c80310d769
46 changed files with 357 additions and 343 deletions

View 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)
})
}
}