From 932b35d71ffc806ff5845ced8a9cb52c0104e883 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Tue, 22 Feb 2022 23:59:39 +0100 Subject: [PATCH] chore: print the url of failed download (#96) --- pkg/registry/http.go | 2 +- pkg/registry/http_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/registry/http.go b/pkg/registry/http.go index 7bfbf44..ecf5ede 100644 --- a/pkg/registry/http.go +++ b/pkg/registry/http.go @@ -80,7 +80,7 @@ func (r SchemaRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8sVers } if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("error while downloading schema - received HTTP status %d", resp.StatusCode) + return nil, fmt.Errorf("error while downloading schema at %s - received HTTP status %d", url, resp.StatusCode) } body, err := ioutil.ReadAll(resp.Body) diff --git a/pkg/registry/http_test.go b/pkg/registry/http_test.go index 3885b70..6abffaa 100644 --- a/pkg/registry/http_test.go +++ b/pkg/registry/http_test.go @@ -61,6 +61,22 @@ func TestDownloadSchema(t *testing.T) { nil, fmt.Errorf("no schema found"), }, + { + "getting 503", + newMockHTTPGetter(func(url string) (resp *http.Response, err error) { + return &http.Response{ + StatusCode: http.StatusServiceUnavailable, + Body: ioutil.NopCloser(strings.NewReader("http response mock body")), + }, nil + }), + "http://kubernetesjson.dev", + true, + "Deployment", + "v1", + "1.18.0", + nil, + fmt.Errorf("error while downloading schema at http://kubernetesjson.dev - received HTTP status 503"), + }, { "200", newMockHTTPGetter(func(url string) (resp *http.Response, err error) {