refactor: rename function and improve error messages

pull/3187/head
Christoph Hösler 7 years ago
parent af9190f956
commit 98e0bd2ecb

@ -229,26 +229,26 @@ func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caF
chartURL := cv.URLs[0]
absoluteChartURL, err := MakeAbsoluteChartURL(repoURL, chartURL)
absoluteChartURL, err := ResolveReferenceURL(repoURL, chartURL)
if err != nil {
return "", err
return "", fmt.Errorf("failed to make chart URL absolute: %v", err)
}
return absoluteChartURL, nil
}
// MakeAbsoluteChartURL resolves chartURL relative to repoURL.
// If chartURL is absolute, it returns chartURL.
func MakeAbsoluteChartURL(repoURL, chartURL string) (string, error) {
parsedRepoURL, err := url.Parse(repoURL)
// ResolveReferenceURL resolves refURL relative to baseURL.
// If refURL is absolute, it simply returns refURL.
func ResolveReferenceURL(baseURL, refURL string) (string, error) {
parsedBaseURL, err := url.Parse(baseURL)
if err != nil {
return "", err
return "", fmt.Errorf("failed to parse %s as URL: %v", baseURL, err)
}
parsedChartURL, err := url.Parse(chartURL)
parsedRefURL, err := url.Parse(refURL)
if err != nil {
return "", err
return "", fmt.Errorf("failed to parse %s as URL: %v", refURL, err)
}
return parsedRepoURL.ResolveReference(parsedChartURL).String(), nil
return parsedBaseURL.ResolveReference(parsedRefURL).String(), nil
}

@ -278,8 +278,8 @@ func TestErrorFindChartInRepoURL(t *testing.T) {
}
}
func TestMakeAbsoluteChartURL(t *testing.T) {
chartURL, err := MakeAbsoluteChartURL("http://localhost:8123/charts/", "nginx-0.2.0.tgz")
func TestResolveReferenceURL(t *testing.T) {
chartURL, err := ResolveReferenceURL("http://localhost:8123/charts/", "nginx-0.2.0.tgz")
if err != nil {
t.Errorf("%s", err)
}
@ -287,7 +287,7 @@ func TestMakeAbsoluteChartURL(t *testing.T) {
t.Errorf("%s", chartURL)
}
chartURL, err = MakeAbsoluteChartURL("http://localhost:8123", "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz")
chartURL, err = ResolveReferenceURL("http://localhost:8123", "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz")
if err != nil {
t.Errorf("%s", err)
}

Loading…
Cancel
Save