(t *testing.T)
| 40 | ) |
| 41 | |
| 42 | func TestResolveChartRef(t *testing.T) { |
| 43 | tests := []struct { |
| 44 | name, ref, expect, version string |
| 45 | fail bool |
| 46 | }{ |
| 47 | {name: "full URL", ref: "http://example.com/foo-1.2.3.tgz", expect: "http://example.com/foo-1.2.3.tgz"}, |
| 48 | {name: "full URL, HTTPS", ref: "https://example.com/foo-1.2.3.tgz", expect: "https://example.com/foo-1.2.3.tgz"}, |
| 49 | {name: "full URL, with authentication", ref: "http://username:password@example.com/foo-1.2.3.tgz", expect: "http://username:password@example.com/foo-1.2.3.tgz"}, |
| 50 | {name: "reference, testing repo", ref: "testing/alpine", expect: "http://example.com/alpine-1.2.3.tgz"}, |
| 51 | {name: "reference, version, testing repo", ref: "testing/alpine", version: "0.2.0", expect: "http://example.com/alpine-0.2.0.tgz"}, |
| 52 | {name: "reference, version, malformed repo", ref: "malformed/alpine", version: "1.2.3", expect: "http://dl.example.com/alpine-1.2.3.tgz"}, |
| 53 | {name: "reference, querystring repo", ref: "testing-querystring/alpine", expect: "http://example.com/alpine-1.2.3.tgz?key=value"}, |
| 54 | {name: "reference, testing-relative repo", ref: "testing-relative/foo", expect: "http://example.com/helm/charts/foo-1.2.3.tgz"}, |
| 55 | {name: "reference, testing-relative repo", ref: "testing-relative/bar", expect: "http://example.com/helm/bar-1.2.3.tgz"}, |
| 56 | {name: "reference, testing-relative repo", ref: "testing-relative/baz", expect: "http://example.com/path/to/baz-1.2.3.tgz"}, |
| 57 | {name: "reference, testing-relative-trailing-slash repo", ref: "testing-relative-trailing-slash/foo", expect: "http://example.com/helm/charts/foo-1.2.3.tgz"}, |
| 58 | {name: "reference, testing-relative-trailing-slash repo", ref: "testing-relative-trailing-slash/bar", expect: "http://example.com/helm/bar-1.2.3.tgz"}, |
| 59 | {name: "encoded URL", ref: "encoded-url/foobar", expect: "http://example.com/with%2Fslash/charts/foobar-4.2.1.tgz"}, |
| 60 | {name: "full URL, HTTPS, irrelevant version", ref: "https://example.com/foo-1.2.3.tgz", version: "0.1.0", expect: "https://example.com/foo-1.2.3.tgz", fail: true}, |
| 61 | {name: "full URL, file", ref: "file:///foo-1.2.3.tgz", fail: true}, |
| 62 | {name: "invalid", ref: "invalid-1.2.3", fail: true}, |
| 63 | {name: "not found", ref: "nosuchthing/invalid-1.2.3", fail: true}, |
| 64 | {name: "ref with tag", ref: "oci://example.com/helm-charts/nginx:15.4.2", expect: "oci://example.com/helm-charts/nginx:15.4.2"}, |
| 65 | {name: "no repository", ref: "oci://", fail: true}, |
| 66 | {name: "oci ref", ref: "oci://example.com/helm-charts/nginx", version: "15.4.2", expect: "oci://example.com/helm-charts/nginx:15.4.2"}, |
| 67 | {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}, |
| 68 | } |
| 69 | |
| 70 | // Create a mock registry client for OCI references |
| 71 | registryClient, err := registry.NewClient() |
| 72 | if err != nil { |
| 73 | t.Fatal(err) |
| 74 | } |
| 75 | |
| 76 | c := ChartDownloader{ |
| 77 | Out: os.Stderr, |
| 78 | RepositoryConfig: repoConfig, |
| 79 | RepositoryCache: repoCache, |
| 80 | RegistryClient: registryClient, |
| 81 | Getters: getter.All(&cli.EnvSettings{ |
| 82 | RepositoryConfig: repoConfig, |
| 83 | RepositoryCache: repoCache, |
| 84 | }), |
| 85 | } |
| 86 | |
| 87 | for _, tt := range tests { |
| 88 | _, u, err := c.ResolveChartVersion(tt.ref, tt.version) |
| 89 | if err != nil { |
| 90 | if tt.fail { |
| 91 | continue |
| 92 | } |
| 93 | t.Errorf("%s: failed with error %q", tt.name, err) |
| 94 | continue |
| 95 | } |
| 96 | if got := u.String(); got != tt.expect { |
| 97 | t.Errorf("%s: expected %s, got %s", tt.name, tt.expect, got) |
| 98 | } |
| 99 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…