From 9ed61d021b6b706c1cb10d8c8880068ec7ff88fc Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Tue, 6 Jun 2023 17:52:37 +0200 Subject: [PATCH] distro/test: update test distro with new behaviour Add a checksum as a hash of URL + Ref. Use the parent ref instead of the image ref when it's set. This makes the test distro always behave like ostree commit and container types (image types that can use an ostree parent) and not raw image or installers (that use ostree commits as a payload). Modify the weldr API test with the expected error message. --- internal/distro/distro_test.go | 5 +++-- internal/distro/test_distro/distro.go | 8 ++++++++ internal/weldr/api_test.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/distro/distro_test.go b/internal/distro/distro_test.go index 71c1d472f..4b17580b6 100644 --- a/internal/distro/distro_test.go +++ b/internal/distro/distro_test.go @@ -1,6 +1,7 @@ package distro_test import ( + "crypto/sha256" "encoding/json" "fmt" "strings" @@ -167,7 +168,7 @@ func TestImageTypePipelineNames(t *testing.T) { assert.NoError(err) containers := make(map[string][]container.Spec, 0) - // "resolve" ostree commits by copying the source specs into commit specs + ostreeSources := m.GetOSTreeSourceSpecs() commits := make(map[string][]ostree.CommitSpec, len(ostreeSources)) for name, commitSources := range ostreeSources { @@ -176,7 +177,7 @@ func TestImageTypePipelineNames(t *testing.T) { commitSpecs[idx] = ostree.CommitSpec{ Ref: commitSource.Ref, URL: commitSource.URL, - Checksum: commitSource.Parent, + Checksum: fmt.Sprintf("%x", sha256.Sum256([]byte(commitSource.URL+commitSource.Ref))), } } commits[name] = commitSpecs diff --git a/internal/distro/test_distro/distro.go b/internal/distro/test_distro/distro.go index d14b0b60f..681a82486 100644 --- a/internal/distro/test_distro/distro.go +++ b/internal/distro/test_distro/distro.go @@ -245,9 +245,17 @@ func (t *TestImageType) Manifest(b *blueprint.Blueprint, options distro.ImageOpt Ref: defaultRef, } if ostreeOptions := options.OSTree; ostreeOptions != nil { + // handle the parameter combo error like we do in distros + if ostreeOptions.ParentRef != "" && ostreeOptions.URL == "" { + // specifying parent ref also requires URL + return nil, nil, ostree.NewParameterComboError("ostree parent ref specified, but no URL to retrieve it") + } if ostreeOptions.ImageRef != "" { // override with ref from image options ostreeSource.Ref = ostreeOptions.ImageRef } + if ostreeOptions.ParentRef != "" { // override with parent ref + ostreeSource.Ref = ostreeOptions.ParentRef + } // copy any other options that might be specified ostreeSource.URL = options.OSTree.URL ostreeSource.RHSM = options.OSTree.RHSM diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 1e7328927..2f636ea7b 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -1165,7 +1165,7 @@ func TestCompose(t *testing.T) { "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"parentid","url":""}}`, test_distro.TestImageTypeOSTree), http.StatusBadRequest, - `{"status": false, "errors":[{"id":"OSTreeOptionsError","msg":"ostree parent ref specified, but no URL to retrieve it"}]}`, + `{"status": false, "errors":[{"id":"ManifestCreationFailed","msg":"failed to initialize osbuild manifest: ostree parent ref specified, but no URL to retrieve it"}]}`, expectedComposeOSTree, []string{"build_id", "warnings"}, },