Manifests test: ensure that every image type has test coverage
Extend the manifests test to ensure that each an every image type of each architecture and each distribution is covered by at least one image test case. Since now we have the ability to generate image test cases for more complicated image types, which consists only of the manifest, we should have test coverage for each and every image type. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
5be81326eb
commit
04f612d758
1 changed files with 36 additions and 0 deletions
|
|
@ -4,11 +4,15 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/distro_test_common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
@ -37,3 +41,35 @@ func TestManifests(t *testing.T) {
|
|||
dnfJsonPath,
|
||||
)
|
||||
}
|
||||
|
||||
// TestImageTestCoverage ensures that each defined image type has
|
||||
// at least one corresponding image test case.
|
||||
func TestImageTestCoverage(t *testing.T) {
|
||||
distroRegistry := distroregistry.NewDefault()
|
||||
for _, distroName := range distroRegistry.List() {
|
||||
distro := distroRegistry.GetDistro(distroName)
|
||||
for _, archName := range distro.ListArches() {
|
||||
missingImgTests := []string{}
|
||||
arch, err := distro.GetArch(archName)
|
||||
require.Nilf(t, err, "failed to get arch %q of distro %q, which was returned in the list of available arches", archName, distroName)
|
||||
for _, imageTypeName := range arch.ListImageTypes() {
|
||||
imageTypeGlob := fmt.Sprintf(
|
||||
"%s/%s-%s-%s*.json",
|
||||
manifestsPath,
|
||||
strings.ReplaceAll(distroName, "-", "_"),
|
||||
strings.ReplaceAll(archName, "-", "_"),
|
||||
strings.ReplaceAll(imageTypeName, "-", "_"),
|
||||
)
|
||||
|
||||
testCaseFiles, err := filepath.Glob(imageTypeGlob)
|
||||
require.Nilf(t, err, "error while globing for image test cases: %v", err)
|
||||
|
||||
if testCaseFiles == nil {
|
||||
missingImgTests = append(missingImgTests, imageTypeName)
|
||||
}
|
||||
}
|
||||
|
||||
assert.Emptyf(t, missingImgTests, "missing image test cases for %q/%q: %v", distroName, archName, missingImgTests)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue