From 929d1b18dd36a24b0686cb0f43e0ea3609660895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Wed, 27 Nov 2024 12:49:38 +0100 Subject: [PATCH] distro: test errors produced when specifying OSTree image options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a common distro unit test, which verifies that specifying OSTree image options for non-OSTree based image types produces an error, while specifying it for OSTree based images doesn't. Signed-off-by: Tomáš Hozza --- pkg/distro/distro_test.go | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/pkg/distro/distro_test.go b/pkg/distro/distro_test.go index 2be669556c..55ac80d483 100644 --- a/pkg/distro/distro_test.go +++ b/pkg/distro/distro_test.go @@ -571,3 +571,63 @@ func TestDistro_ManifestFIPSWarning(t *testing.T) { } } } + +// Test that passing options.OSTree for non-OSTree image types results in an error +func TestOSTreeOptionsErrorForNonOSTreeImgTypes(t *testing.T) { + assert := assert.New(t) + distroFactory := distrofactory.NewDefault() + assert.NotNil(distroFactory) + + distros := distro_test_common.ListTestedDistros(t) + assert.NotEmpty(distros) + + for _, distroName := range distros { + d := distroFactory.GetDistro(distroName) + assert.NotNil(d) + + arches := d.ListArches() + assert.NotEmpty(arches) + + for _, archName := range arches { + arch, err := d.GetArch(archName) + assert.Nil(err) + + imgTypes := arch.ListImageTypes() + assert.NotEmpty(imgTypes) + + for _, imageTypeName := range imgTypes { + t.Run(fmt.Sprintf("%s/%s/%s", distroName, archName, imageTypeName), func(t *testing.T) { + imageType, err := arch.GetImageType(imageTypeName) + assert.Nil(err) + + // set up bare minimum args for image type + var customizations *blueprint.Customizations + if imageType.Name() == "edge-simplified-installer" || imageType.Name() == "iot-simplified-installer" { + customizations = &blueprint.Customizations{ + InstallationDevice: "/dev/null", + } + } + bp := blueprint.Blueprint{ + Customizations: customizations, + } + options := distro.ImageOptions{ + OSTree: &ostree.ImageOptions{ + URL: "https://example.com", + }, + } + + _, _, err = imageType.Manifest(&bp, options, nil, 0) + if imageType.OSTreeRef() == "" { + assert.Errorf(err, + "OSTree options should not be allowed for non-OSTree image type %s/%s/%s", + imageTypeName, archName, distroName) + } else { + assert.NoErrorf(err, + "OSTree options should be allowed for OSTree image type %s/%s/%s", + imageTypeName, archName, distroName) + } + }) + } + } + } +}