From 10c4c253a2d59d47d110f7c6920832295b0b41e9 Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Thu, 4 Dec 2025 16:48:36 +0000 Subject: [PATCH] Move oci registry push result to a struct Signed-off-by: Evans Mungai --- pkg/cmd/pull_test.go | 6 +++--- pkg/repo/v1/repotest/server.go | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/pull_test.go b/pkg/cmd/pull_test.go index 36efe7b7f..1c5af3146 100644 --- a/pkg/cmd/pull_test.go +++ b/pkg/cmd/pull_test.go @@ -520,7 +520,7 @@ func TestPullOCIWithTagAndDigest(t *testing.T) { if err != nil { t.Fatal(err) } - ociSrv.Run(t) + result := ociSrv.Run(t) contentCache := t.TempDir() outdir := t.TempDir() @@ -528,7 +528,7 @@ func TestPullOCIWithTagAndDigest(t *testing.T) { // Test: pull with tag and digest (the fixed bug from issue #31600) // Previously this failed with "encoding/hex: invalid byte: U+0073 's'" ref := fmt.Sprintf("oci://%s/u/ocitestuser/oci-dependent-chart:0.1.0@%s", - ociSrv.RegistryURL, ociSrv.ManifestDigest) + ociSrv.RegistryURL, result.PushedChart.Manifest.Digest) cmd := fmt.Sprintf("pull %s -d '%s' --registry-config %s --content-cache %s --plain-http", ref, @@ -547,7 +547,7 @@ func TestPullOCIWithTagAndDigest(t *testing.T) { expectedFile := filepath.Join(outdir, "oci-dependent-chart-0.1.0.tgz") if _, err := os.Stat(expectedFile); err != nil { // Try the digest-based filename - digestPart := ociSrv.ManifestDigest[7:] // strip "sha256:" + digestPart := result.PushedChart.Manifest.Digest[7:] // strip "sha256:" expectedFile = filepath.Join(outdir, fmt.Sprintf("oci-dependent-chart@sha256-%s.tgz", digestPart)) if _, err := os.Stat(expectedFile); err != nil { t.Errorf("expected chart file not found: %v", err) diff --git a/pkg/repo/v1/repotest/server.go b/pkg/repo/v1/repotest/server.go index 2e27e1ed9..6380e1a86 100644 --- a/pkg/repo/v1/repotest/server.go +++ b/pkg/repo/v1/repotest/server.go @@ -140,12 +140,11 @@ func newServer(t *testing.T, docroot string, options ...ServerOption) *Server { type OCIServer struct { *registry.Registry - RegistryURL string - Dir string - TestUsername string - TestPassword string - Client *ociRegistry.Client - ManifestDigest string // Digest of the pushed oci-dependent-chart manifest + RegistryURL string + Dir string + TestUsername string + TestPassword string + Client *ociRegistry.Client } type OCIServerRunConfig struct { @@ -154,6 +153,10 @@ type OCIServerRunConfig struct { type OCIServerOpt func(config *OCIServerRunConfig) +type OCIServerRunResult struct { + PushedChart *ociRegistry.PushResult +} + func WithDependingChart(c *chart.Chart) OCIServerOpt { return func(config *OCIServerRunConfig) { config.DependingChart = c @@ -210,7 +213,7 @@ func NewOCIServer(t *testing.T, dir string) (*OCIServer, error) { }, nil } -func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) { +func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) *OCIServerRunResult { t.Helper() cfg := &OCIServerRunConfig{} for _, fn := range opts { @@ -283,10 +286,11 @@ func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) { result.Chart.Digest, result.Chart.Size) srv.Client = registryClient - srv.ManifestDigest = result.Manifest.Digest c := cfg.DependingChart if c == nil { - return + return &OCIServerRunResult{ + PushedChart: result, + } } dependingRef := fmt.Sprintf("%s/u/ocitestuser/%s:%s", @@ -310,6 +314,10 @@ func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) { result.Manifest.Digest, result.Manifest.Size, result.Config.Digest, result.Config.Size, result.Chart.Digest, result.Chart.Size) + + return &OCIServerRunResult{ + PushedChart: result, + } } // Root gets the docroot for the server.