Skip to content

Commit 6d1afd0

Browse files
tests
1 parent 9d58dab commit 6d1afd0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

utils/api/api_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ func TestCheckAPICallSuccess(t *testing.T) {
5858
assert.Equal(t, actualErr.Error(), expectedErr)
5959
})
6060

61+
t.Run("api call not successful (no JSON response)", func(t *testing.T) {
62+
errMessage := "response error"
63+
parentCtx := context.Background()
64+
resp := _http.Response{StatusCode: 403, Body: io.NopCloser(bytes.NewReader([]byte("<html><head><title>403 Forbidden</title></head></html>")))}
65+
actualErr := CheckAPICallSuccess(parentCtx, errMessage, &resp, errors.New("403 Forbidden"))
66+
expectedErr := "response error (403): <html><head><title>403 Forbidden</title></head></html>; 403 Forbidden"
67+
assert.Equal(t, actualErr.Error(), expectedErr)
68+
})
69+
6170
t.Run("no context error, api call successful", func(t *testing.T) {
6271
errMessage := "no error"
6372
parentCtx := context.Background()

utils/errors/errors_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ func TestFetchAPIErrorDescription(t *testing.T) {
4545
expectedMessage := ""
4646
assert.Equal(t, expectedMessage, actualMessage)
4747
})
48+
49+
t.Run("error response is not JSON", func(t *testing.T) {
50+
resp := _http.Response{Body: io.NopCloser(bytes.NewReader([]byte("<html><head><title>403 Forbidden</title></head></html>")))}
51+
actualMessage := FetchAPIErrorDescription(&resp)
52+
expectedMessage := "<html><head><title>403 Forbidden</title></head></html>"
53+
assert.Equal(t, expectedMessage, actualMessage)
54+
})
4855
}
4956

5057
func TestFetchAPIErrorDescriptionInterrupt(t *testing.T) {

0 commit comments

Comments
 (0)