@@ -16,6 +16,7 @@ limitations under the License.
1616package downloader
1717
1818import (
19+ "fmt"
1920 "os"
2021 "path/filepath"
2122 "testing"
@@ -35,7 +36,7 @@ const (
3536func TestResolveChartRef (t * testing.T ) {
3637 tests := []struct {
3738 name , ref , expect , version string
38- fail bool
39+ expectError string
3940 }{
4041 {name : "full URL" , ref : "http://example.com/foo-1.2.3.tgz" , expect : "http://example.com/foo-1.2.3.tgz" },
4142 {name : "full URL, HTTPS" , ref : "https://example.com/foo-1.2.3.tgz" , expect : "https://example.com/foo-1.2.3.tgz" },
@@ -51,10 +52,10 @@ func TestResolveChartRef(t *testing.T) {
5152 {name : "reference, testing-relative-trailing-slash repo" , ref : "testing-relative-trailing-slash/foo" , expect : "http://example.com/helm/charts/foo-1.2.3.tgz" },
5253 {name : "reference, testing-relative-trailing-slash repo" , ref : "testing-relative-trailing-slash/bar" , expect : "http://example.com/helm/bar-1.2.3.tgz" },
5354 {name : "encoded URL" , ref : "encoded-url/foobar" , expect : "http://example.com/with%2Fslash/charts/foobar-4.2.1.tgz" },
54- {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 },
55- {name : "full URL, file" , ref : "file:///foo-1.2.3.tgz" , fail : true },
56- {name : "invalid" , ref : "invalid-1.2.3" , fail : true },
57- {name : "not found" , ref : "nosuchthing/invalid-1.2.3" , fail : true },
55+ {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" },
56+ {name : "full URL, file" , ref : "file:///foo-1.2.3.tgz" , expectError : "repo not found" },
57+ {name : "invalid" , ref : "invalid-1.2.3" , expectError : "non-absolute URLs should be in form of repo_name/path_to_chart, got: invalid-1.2.3" },
58+ {name : "not found" , ref : "nosuchthing/invalid-1.2.3" , expectError : "repo nosuchthing not found" },
5859 }
5960
6061 c := ChartDownloader {
@@ -69,10 +70,13 @@ func TestResolveChartRef(t *testing.T) {
6970
7071 for _ , tt := range tests {
7172 u , err := c .ResolveChartVersion (tt .ref , tt .version )
72- if err != nil {
73- if tt .fail {
74- continue
73+ if tt . expectError != "" {
74+ if tt .expectError != fmt . Sprint ( err ) {
75+ t . Errorf ( "%s: expected error %q, got %q" , tt . name , tt . expectError , err )
7576 }
77+ continue
78+ }
79+ if err != nil {
7680 t .Errorf ("%s: failed with error %q" , tt .name , err )
7781 continue
7882 }
0 commit comments