diff --git a/scalr.go b/scalr.go index f755ad6..16eb01c 100644 --- a/scalr.go +++ b/scalr.go @@ -444,7 +444,7 @@ func checkResponseCode(r *http.Response) error { err := json.NewDecoder(r.Body).Decode(errPayload) if err != nil || len(errPayload.Errors) == 0 { if r.StatusCode == 404 { - return &ErrResourceNotFound{} + return ErrResourceNotFound{} } else { return fmt.Errorf(r.Status) } diff --git a/scalr_test.go b/scalr_test.go index be3e21f..a6858f0 100644 --- a/scalr_test.go +++ b/scalr_test.go @@ -1,8 +1,11 @@ package scalr import ( + "bytes" "context" "errors" + "github.com/stretchr/testify/assert" + "io/ioutil" "net/http" "net/http/httptest" "os" @@ -245,6 +248,19 @@ func TestClient_retryHTTPCheck(t *testing.T) { } } +func TestClient_notFoundErrorWithoutMessage(t *testing.T) { + resp := &http.Response{ + StatusCode: 404, + Body: ioutil.NopCloser(bytes.NewBufferString("test boody")), + } + err := checkResponseCode(resp) + + if err != nil { + assert.Error(t, err) + assert.Equal(t, err, ErrResourceNotFound{}) + } +} + func setupEnvVars(token, address string) func() { origToken := os.Getenv("SCALR_TOKEN") origAddress := os.Getenv("SCALR_ADDRESS")