From a19c40ddcadf9984460e85d7d3222b55d24b9196 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Thu, 13 Jun 2024 17:39:08 +0200 Subject: [PATCH] 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 --- pkg/downloader/chart_downloader_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/downloader/chart_downloader_test.go b/pkg/downloader/chart_downloader_test.go index dd82c20d6..cf7992267 100644 --- a/pkg/downloader/chart_downloader_test.go +++ b/pkg/downloader/chart_downloader_test.go @@ -16,6 +16,7 @@ limitations under the License. package downloader import ( + "fmt" "os" "path/filepath" "testing" @@ -37,6 +38,8 @@ const ( ) func TestResolveChartRef(t *testing.T) { + ociRegistryUrl := "localhost:5000" + tests := []struct { name, ref, expect, version string fail bool @@ -61,6 +64,13 @@ func TestResolveChartRef(t *testing.T) { {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 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()