feat: add strong distro type for wolfi (#996)

This commit is contained in:
Weston Steimel 2022-11-15 15:25:46 +00:00 committed by GitHub
parent 3e0af43383
commit ef1934a5c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 1 deletions

View file

@ -71,6 +71,8 @@ func NamespaceForDistro(d *distro.Distro) string {
return fmt.Sprintf("sles:%d.%d", versionSegments[0], versionSegments[1])
case distro.Windows:
return fmt.Sprintf("%s:%d", MSRCNamespacePrefix, versionSegments[0])
case distro.Wolfi:
return "wolfi:rolling"
}
}
return fmt.Sprintf("%s:%s", strings.ToLower(d.Type.String()), d.FullVersion())

View file

@ -178,9 +178,14 @@ func Test_NamespaceForDistro(t *testing.T) {
},
{
dist: distro.Gentoo,
version: "", // Gentoo doesn't expose a version
version: "", // Gentoo is a rolling release
expected: "gentoo:",
},
{
dist: distro.Wolfi,
version: "2022yzblah", // Wolfi is a rolling release
expected: "wolfi:rolling",
},
}
observedDistros := strset.New()

View file

@ -37,6 +37,10 @@ func TestFromString(t *testing.T) {
namespaceString: "amazon:distro:amazonlinux:2",
result: NewNamespace("amazon", grypeDistro.AmazonLinux, "2"),
},
{
namespaceString: "wolfi:distro:wolfi:rolling",
result: NewNamespace("wolfi", grypeDistro.Wolfi, "rolling"),
},
}
for _, test := range successTests {

View file

@ -37,6 +37,10 @@ func TestFromString(t *testing.T) {
namespaceString: "amazon:distro:amazonlinux:2",
result: NewNamespace("amazon", grypeDistro.AmazonLinux, "2"),
},
{
namespaceString: "wolfi:distro:wolfi:rolling",
result: NewNamespace("wolfi", grypeDistro.Wolfi, "rolling"),
},
}
for _, test := range successTests {

View file

@ -204,6 +204,10 @@ func Test_NewDistroFromRelease_Coverage(t *testing.T) {
fixture: "test-fixtures/os/gentoo",
Type: Gentoo,
},
{
fixture: "test-fixtures/os/wolfi",
Type: Wolfi,
},
}
observedDistros := internal.NewStringSet()

View file

@ -0,0 +1,5 @@
ID=wolfi
NAME="Wolfi"
PRETTY_NAME="Wolfi"
VERSION_ID="20220914"
HOME_URL="https://wolfi.dev"

View file

@ -28,6 +28,7 @@ const (
RockyLinux Type = "rockylinux"
AlmaLinux Type = "almalinux"
Gentoo Type = "gentoo"
Wolfi Type = "wolfi"
)
// All contains all Linux distribution options
@ -50,6 +51,7 @@ var All = []Type{
RockyLinux,
AlmaLinux,
Gentoo,
Wolfi,
}
// IDMapping connects a distro ID like "ubuntu" to a Distro type
@ -72,6 +74,7 @@ var IDMapping = map[string]Type{
"rocky": RockyLinux,
"almalinux": AlmaLinux,
"gentoo": Gentoo,
"wolfi": Wolfi,
}
func TypeFromRelease(release linux.Release) Type {