Move oci registry push result to a struct

Signed-off-by: Evans Mungai <mbuevans@gmail.com>
pull/31601/head
Evans Mungai 10 months 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
ociSrv.Run(t) result := ociSrv.Run(t)
contentCache := t.TempDir() contentCache := t.TempDir()
outdir := 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) // Test: pull with tag and digest (the fixed bug from issue #31600)
// Previously this failed with "encoding/hex: invalid byte: U+0073 's'" // 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", 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", cmd := fmt.Sprintf("pull %s -d '%s' --registry-config %s --content-cache %s --plain-http",
ref, ref,
@ -547,7 +547,7 @@ func TestPullOCIWithTagAndDigest(t *testing.T) {
expectedFile := filepath.Join(outdir, "oci-dependent-chart-0.1.0.tgz") expectedFile := filepath.Join(outdir, "oci-dependent-chart-0.1.0.tgz")
if _, err := os.Stat(expectedFile); err != nil { if _, err := os.Stat(expectedFile); err != nil {
// Try the digest-based filename // 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)) expectedFile = filepath.Join(outdir, fmt.Sprintf("oci-dependent-chart@sha256-%s.tgz", digestPart))
if _, err := os.Stat(expectedFile); err != nil { if _, err := os.Stat(expectedFile); err != nil {
t.Errorf("expected chart file not found: %v", err) t.Errorf("expected chart file not found: %v", err)

@ -145,7 +145,6 @@ type OCIServer struct {
TestUsername string TestUsername string
TestPassword string TestPassword string
Client *ociRegistry.Client Client *ociRegistry.Client
ManifestDigest string // Digest of the pushed oci-dependent-chart manifest
} }
type OCIServerRunConfig struct { type OCIServerRunConfig struct {
@ -154,6 +153,10 @@ type OCIServerRunConfig struct {
type OCIServerOpt func(config *OCIServerRunConfig) type OCIServerOpt func(config *OCIServerRunConfig)
type OCIServerRunResult struct {
PushedChart *ociRegistry.PushResult
}
func WithDependingChart(c *chart.Chart) OCIServerOpt { func WithDependingChart(c *chart.Chart) OCIServerOpt {
return func(config *OCIServerRunConfig) { return func(config *OCIServerRunConfig) {
config.DependingChart = c config.DependingChart = c
@ -210,7 +213,7 @@ func NewOCIServer(t *testing.T, dir string) (*OCIServer, error) {
}, nil }, nil
} }
func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) { func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) *OCIServerRunResult {
t.Helper() t.Helper()
cfg := &OCIServerRunConfig{} cfg := &OCIServerRunConfig{}
for _, fn := range opts { for _, fn := range opts {
@ -283,10 +286,11 @@ func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) {
result.Chart.Digest, result.Chart.Size) result.Chart.Digest, result.Chart.Size)
srv.Client = registryClient srv.Client = registryClient
srv.ManifestDigest = result.Manifest.Digest
c := cfg.DependingChart c := cfg.DependingChart
if c == nil { if c == nil {
return return &OCIServerRunResult{
PushedChart: result,
}
} }
dependingRef := fmt.Sprintf("%s/u/ocitestuser/%s:%s", 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.Manifest.Digest, result.Manifest.Size,
result.Config.Digest, result.Config.Size, result.Config.Digest, result.Config.Size,
result.Chart.Digest, result.Chart.Size) result.Chart.Digest, result.Chart.Size)
return &OCIServerRunResult{
PushedChart: result,
}
} }
// Root gets the docroot for the server. // Root gets the docroot for the server.

Loading…
Cancel
Save