From 351748d7fc64ce17db4e3458a1eda55ce5a0be60 Mon Sep 17 00:00:00 2001 From: Paul Mars Date: Wed, 16 Oct 2024 10:25:49 +0200 Subject: [PATCH] tests: Make testHelperCheckArtifacts flexible to qemu version used The file output may depend on the qemu version used. Match both cases so tests can be run on different series. Signed-off-by: Paul Mars --- internal/statemachine/classic_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/statemachine/classic_test.go b/internal/statemachine/classic_test.go index 3b1f0879..ccf1ac8a 100644 --- a/internal/statemachine/classic_test.go +++ b/internal/statemachine/classic_test.go @@ -3010,7 +3010,7 @@ func TestSuccessfulClassicRun(t *testing.T) { artifacts := map[string]string{ "pc-amd64.img": "DOS/MBR boot sector", - "pc-amd64.qcow2": "QEMU QCOW2 Image (v3)", + "pc-amd64.qcow2": `QEMU QCOW2? Image \(v3\)`, "filesystem-manifest.txt": "text", "filesystem-filelist.txt": "text", } @@ -3171,7 +3171,10 @@ func testHelperCheckArtifacts(t *testing.T, asserter *helper.Asserter, outputDir fileCommand := *exec.Command("file", fullPath) cmdOutput, err := fileCommand.CombinedOutput() asserter.AssertErrNil(err, true) - if !strings.Contains(string(cmdOutput), fileType) { + + fileTypeRegex := regexp.MustCompile(fileType) + + if !fileTypeRegex.Match([]byte(cmdOutput)) { t.Errorf("File \"%s\" is the wrong file type. Expected \"%s\" but got \"%s\"", fullPath, fileType, string(cmdOutput)) }