fix: prevent panic when ChartDownloader.getOciURI

needs to lookup tags because no version is provided
but no RegistryClient is provided

Add tests for oci registries

Signed-off-by: Carlos Sanchez <carlos@apache.org>
pull/13105/head
Carlos Sanchez 1 year ago
parent 72f5f36e2f
commit a19c40ddca

@ -16,6 +16,7 @@ limitations under the License.
package downloader package downloader
import ( import (
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -37,6 +38,8 @@ const (
) )
func TestResolveChartRef(t *testing.T) { func TestResolveChartRef(t *testing.T) {
ociRegistryUrl := "localhost:5000"
tests := []struct { tests := []struct {
name, ref, expect, version string name, ref, expect, version string
fail bool fail bool
@ -61,6 +64,13 @@ func TestResolveChartRef(t *testing.T) {
{name: "no repository", ref: "oci://", fail: true}, {name: "no repository", ref: "oci://", fail: true},
{name: "oci ref", ref: "oci://example.com/helm-charts/nginx", version: "15.4.2", expect: "oci://example.com/helm-charts/nginx:15.4.2"}, {name: "oci ref", ref: "oci://example.com/helm-charts/nginx", version: "15.4.2", expect: "oci://example.com/helm-charts/nginx:15.4.2"},
{name: "oci ref with sha256 and version mismatch", ref: "oci://example.com/install/by/sha:0.1.1@sha256:d234555386402a5867ef0169fefe5486858b6d8d209eaf32fd26d29b16807fd6", version: "0.1.2", fail: true}, {name: "oci ref with sha256 and version mismatch", ref: "oci://example.com/install/by/sha:0.1.1@sha256:d234555386402a5867ef0169fefe5486858b6d8d209eaf32fd26d29b16807fd6", version: "0.1.2", fail: true},
// OCI tests
{name: "OCI with version", ref: fmt.Sprintf("oci://%s/u/ocitestuser/oci-dependent-chart", ociRegistryUrl), version: "0.1.0",
expect: fmt.Sprintf("oci://%s/u/ocitestuser/oci-dependent-chart:0.1.0", ociRegistryUrl)},
{name: "OCI without version fails without registry client", ref: fmt.Sprintf("oci://%s/u/ocitestuser/oci-dependent-chart", ociRegistryUrl),
expect: fmt.Sprintf("oci://%s/u/ocitestuser/oci-dependent-chart:0.1.0", ociRegistryUrl), fail: true},
{name: "not found", ref: "oci://localhost:9999/nosuchthing/invalid-1.2.3", fail: true},
} }
registryClient, err := registry.NewClient() registryClient, err := registry.NewClient()

Loading…
Cancel
Save