Merge pull request #447 from bureado/main

Minimal changes to use ID_LIKE
This commit is contained in:
Alex Goodman 2021-08-12 14:20:13 -04:00 committed by GitHub
commit 6f038e9208
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 3 deletions

View file

@ -91,10 +91,15 @@ func assemble(name, version, like string) *Distro {
distroType, ok := IDMapping[name]
// Both distro and version must be present
if len(name) == 0 {
if len(name) == 0 && len(version) == 0 {
return nil
}
// If it's an unknown distro, try mapping the ID_LIKE
if !ok && len(like) != 0 {
distroType, ok = IDMapping[like]
}
if ok {
distro, err := NewDistro(distroType, version, like)
if err != nil {

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