grype/vulnscan/vulnerability/namespace_test.go

104 lines
2 KiB
Go

package vulnerability
import (
"fmt"
"testing"
"github.com/anchore/imgbom/imgbom/distro"
)
func TestDistroNamespace_AllDistros(t *testing.T) {
tests := []struct {
dist distro.Type
version string
expected string
}{
{
dist: distro.Debian,
version: "8",
expected: "debian:8",
},
{
dist: distro.Busybox,
version: "3.1.1",
expected: "busybox:3.1.1",
},
{
dist: distro.CentOS,
version: "7",
expected: "rhel:7",
},
{
dist: distro.Ubuntu,
version: "18.04",
expected: "ubuntu:18.04",
},
{
dist: distro.RedHat,
version: "6",
expected: "rhel:6",
},
}
for _, test := range tests {
name := fmt.Sprintf("%s:%s", test.dist, test.version)
t.Run(name, func(t *testing.T) {
d, err := distro.NewDistro(test.dist, test.version)
if err != nil {
t.Errorf("could not create distro='%+v:%+v': %+v", test.dist, test.version, err)
}
actual := distroNamespace(d)
if actual != test.expected {
t.Errorf("mismatched distro namespace: '%s'!='%s'", actual, test.expected)
}
})
}
if len(tests) != len(distro.All) {
t.Errorf("probably excluded a distro in namespace name testing")
}
}
func TestDistroNamespace_VersionHandeling(t *testing.T) {
tests := []struct {
dist distro.Type
version string
expected string
}{
{
dist: distro.Debian,
version: "8",
expected: "debian:8",
},
{
dist: distro.Debian,
version: "18.04",
expected: "debian:18.04",
},
{
dist: distro.Debian,
version: "0",
expected: "debian:0",
},
}
for _, test := range tests {
name := fmt.Sprintf("%s:%s", test.dist, test.version)
t.Run(name, func(t *testing.T) {
d, err := distro.NewDistro(test.dist, test.version)
if err != nil {
t.Errorf("could not create distro='%+v:%+v': %+v", test.dist, test.version, err)
}
actual := distroNamespace(d)
if actual != test.expected {
t.Errorf("mismatched distro namespace: '%s'!='%s'", actual, test.expected)
}
})
}
}