Files
trivy/pkg/scanner/utils/utils_test.go
Teppei Fukuda b6d5b82c48 fix: version comparison (#740)
* feat: add comparer

* refactor: rename lang with ecosystem

* feat(bundler): add comparer

* feat(node): add comparer

* feat(bundler): integrate comparer

* feat(cargo): integrate comparer

* feat(composer): add comparer

* feat(ghsa): integrate comparer

* feat(node): integrate comparer

* feat(python): integrate comparer

* test(bundler): add tests

* test(cargo): add tests

* test(composer): add tests

* test(ghsa): add tests

* test(node): add tests

* test(python): add tests

* refactor(utils): remove unnecessary functions

* test(utils): add tests

* test: rename bucket prefixes

* fix(detect): use string

* chore: update dependencies

* docs: add comments

* fix(cargo): handle unpatched vulnerability

* test(db): update trivy-db for integration tests

* test(integration): update a golden file

* test(cargo): Add a case for missing patched version

Signed-off-by: Simarpreet Singh <simar@linux.com>

* refactor(advisory): update comments

* refactor(node/advisory): change the receiver

* chore(mod): update dependencies

* refactor(comparer): unexport MatchVersion

* refactor: fix maligned structs

* test(node): add empty value

* refactor

* refactor: sort imports

* chore(mod): update trivy-db

Co-authored-by: Simarpreet Singh <simar@linux.com>
2020-11-17 11:38:58 +02:00

74 lines
1.2 KiB
Go

package utils
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/aquasecurity/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)
})
}
}