test/image: fix pipeline exports for v2 manifests

Previously, we just assumed that all test manifests are of version 1, or we
should export the pipeline named assembler. However, this is no longer true
in RHEL 8.5 and 9 - they are only manifest v2 and they don't have a pipeline
named assembler.

This commit introduces a new way to guess the export name - if the manifest
is of version 1, we just export the assembler. In the case v2 manifest, the
last pipeline is exported.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2021-08-16 12:56:55 +02:00 committed by Ondřej Budai
parent 097eb9f04f
commit 1516c1987e

View file

@ -482,6 +482,34 @@ func testImage(t *testing.T, testcase testcaseStruct, imagePath string) {
}
}
// guessPipelineToExport return a best-effort guess about which
// pipeline should be exported when running osbuild for the testcase
//
// If this function detects that this is a version 1 manifest, it
// always returns "assembler"
//
// For manifests version 2, the name of the last pipeline is returned.
func guessPipelineToExport(rawManifest json.RawMessage) string {
const v1ManifestExportName = "assembler"
var v2Manifest struct {
Version string `json:"version"`
Pipelines []struct {
Name string `json:"name,omitempty"`
} `json:"pipelines"`
}
err := json.Unmarshal(rawManifest, &v2Manifest)
if err != nil {
// if we cannot unmarshal, let's just assume that it's a version 1 manifest
return v1ManifestExportName
}
if v2Manifest.Version == "2" {
return v2Manifest.Pipelines[len(v2Manifest.Pipelines)-1].Name
}
return v1ManifestExportName
}
// runTestcase builds the pipeline specified in the testcase and then it
// tests the result
func runTestcase(t *testing.T, testcase testcaseStruct, store string) {
@ -494,9 +522,7 @@ func runTestcase(t *testing.T, testcase testcaseStruct, store string) {
require.NoError(t, err, "error removing temporary output directory")
}()
// NOTE(akoutsou) 1to2t: new v2 manifests name their last pipeline
// "assembler" for compatibility with v1
exports := []string{"assembler"}
exports := []string{guessPipelineToExport(testcase.Manifest)}
err = runOsbuild(testcase.Manifest, store, outputDirectory, exports)
require.NoError(t, err)