add unit tests for distro identification based on "like" field

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2021-08-12 14:09:22 -04:00
parent c833472b6e
commit 32a54b94be
No known key found for this signature in database
GPG Key ID: 5CB45AE22BAB7EA7
5 changed files with 25 additions and 4 deletions

View File

@ -97,8 +97,7 @@ func assemble(name, version, like string) *Distro {
// If it's an unknown distro, try mapping the ID_LIKE
if !ok && len(like) != 0 {
name = like
distroType, ok = IDMapping[name]
distroType, ok = IDMapping[like]
}
if ok {

View File

@ -7,9 +7,8 @@ import (
"testing"
"github.com/anchore/syft/internal"
"github.com/stretchr/testify/assert"
"github.com/anchore/syft/syft/source"
"github.com/stretchr/testify/assert"
)
func TestIdentifyDistro(t *testing.T) {
@ -85,6 +84,20 @@ func TestIdentifyDistro(t *testing.T) {
fixture: "test-fixtures/os/arch",
Type: ArchLinux,
},
{
fixture: "test-fixtures/partial-fields/missing-id",
Type: Debian,
Version: "8.0.0",
},
{
fixture: "test-fixtures/partial-fields/unknown-id",
Type: Debian,
Version: "8.0.0",
},
{
fixture: "test-fixtures/partial-fields/missing-version",
Type: UnknownDistroType,
},
}
observedDistros := internal.NewStringSet()

View File

@ -0,0 +1,3 @@
NAME="Debian GNU/Linux"
VERSION_ID="8"
ID_LIKE=debian

View File

@ -0,0 +1,2 @@
NAME="Debian GNU/Linux"
ID_LIKE=debian

View File

@ -0,0 +1,4 @@
NAME="Debian GNU/Linux"
VERSION_ID="8"
ID=my-awesome-distro
ID_LIKE=debian