Move oci registry push result to a struct

Signed-off-by: Evans Mungai <mbuevans@gmail.com>
pull/31601/head
Evans Mungai 4 weeks ago
parent 9b34535a84
commit 10c4c253a2
No known key found for this signature in database
GPG Key ID: BBEB812143DD14E1

@ -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)

@ -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.

Loading…
Cancel
Save