distro/*: test kernels in image types

Test that all defined image types return at least one kernel when given
an empty blueprint and exactly one kernel for ostree-commit types.
This commit is contained in:
Achilleas Koutsou 2021-02-01 15:17:18 +01:00 committed by Tom Gundersen
parent 8d9753a4c2
commit 1ef1bab5a8
5 changed files with 59 additions and 0 deletions

View file

@ -111,3 +111,46 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, distr
})
}
}
func isOSTree(imgType distro.ImageType) bool {
for _, pkg := range imgType.BuildPackages() {
if pkg == "rpm-ostree" {
return true
}
}
return false
}
var knownKernels = []string{"kernel", "kernel-debug", "kernel-rt"}
// Returns the number of known kernels in the package list
func kernelCount(imgType distro.ImageType) int {
pkgs, _ := imgType.Packages(blueprint.Blueprint{})
n := 0
for _, pkg := range pkgs {
for _, kernel := range knownKernels {
if kernel == pkg {
n++
}
}
}
return n
}
func TestDistro_KernelOption(t *testing.T, d distro.Distro) {
for _, archName := range d.ListArches() {
arch, err := d.GetArch(archName)
assert.NoError(t, err)
for _, typeName := range arch.ListImageTypes() {
imgType, err := arch.GetImageType(typeName)
assert.NoError(t, err)
nk := kernelCount(imgType)
// at least one kernel for general image types
// exactly one kernel for OSTree commits
if nk < 1 || (isOSTree(imgType) && nk != 1) {
assert.Fail(t, fmt.Sprintf("%s Kernel count", d.Name()),
"Image type %s (arch %s) specifies %d Kernel packages", typeName, archName, nk)
}
}
}
}

View file

@ -369,3 +369,7 @@ func TestFedora32_ModulePlatformID(t *testing.T) {
distro := fedora32.New()
assert.Equal(t, "platform:f32", distro.ModulePlatformID())
}
func TestFedora32_KernelOption(t *testing.T) {
distro_test_common.TestDistro_KernelOption(t, fedora32.New())
}

View file

@ -375,3 +375,7 @@ func TestFedora33_ModulePlatformID(t *testing.T) {
distro := fedora33.New()
assert.Equal(t, "platform:f33", distro.ModulePlatformID())
}
func TestFedora33_KernelOption(t *testing.T) {
distro_test_common.TestDistro_KernelOption(t, fedora33.New())
}

View file

@ -433,3 +433,7 @@ func TestRhel8_ModulePlatformID(t *testing.T) {
distro := rhel8.New()
assert.Equal(t, "platform:el8", distro.ModulePlatformID())
}
func TestRhel8_KernelOption(t *testing.T) {
distro_test_common.TestDistro_KernelOption(t, rhel8.New())
}

View file

@ -586,3 +586,7 @@ func TestRhel84_ModulePlatformID(t *testing.T) {
centos := rhel84.NewCentos()
assert.Equal(t, "platform:el8", centos.ModulePlatformID())
}
func TestRhel84_KernelOption(t *testing.T) {
distro_test_common.TestDistro_KernelOption(t, rhel84.New())
}