forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request linode#144 from Charliekenney23/fix/handle-non-jso…
…n-errors handle Linode API default 502 response
- Loading branch information
Showing
5 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package linodego | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/go-resty/resty/v2" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestCoupleAPIErrors_badGatewayError(t *testing.T) { | ||
rawResponse := []byte(`<html> | ||
<head><title>502 Bad Gateway</title></head> | ||
<body bgcolor="white"> | ||
<center><h1>502 Bad Gateway</h1></center> | ||
<hr><center>nginx</center> | ||
</body> | ||
</html>`) | ||
buf := ioutil.NopCloser(bytes.NewBuffer(rawResponse)) | ||
|
||
resp := &resty.Response{ | ||
Request: &resty.Request{ | ||
Error: errors.New("Bad Gateway"), | ||
}, | ||
RawResponse: &http.Response{ | ||
Header: http.Header{ | ||
"Content-Type": []string{"text/html"}, | ||
}, | ||
StatusCode: http.StatusBadGateway, | ||
Body: buf, | ||
}, | ||
} | ||
|
||
expectedError := Error{ | ||
Code: http.StatusBadGateway, | ||
Message: http.StatusText(http.StatusBadGateway), | ||
} | ||
|
||
if _, err := coupleAPIErrors(resp, nil); !cmp.Equal(err, expectedError) { | ||
t.Errorf("expected error %#v to match error %#v", err, expectedError) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters