Skip to content

Commit

Permalink
Add error test
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Jun 14, 2024
1 parent da5ab76 commit a59faf4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,30 @@ func Test_GetQueryResultsStruct_OK(t *testing.T) {
)
}

func Test_GetQueryResultsStruct_Err(t *testing.T) {
assert := assert.New(t)
httpmock.Activate()
defer httpmock.DeactivateAndReset()

httpmock.RegisterResponder(http.MethodGet, "https://redash.example.com/api/queries/1/results.json", func(req *http.Request) (*http.Response, error) {
assert.Equal(
http.Header(
http.Header{
"Authorization": []string{"Key " + testRedashAPIKey},
"Content-Type": []string{"application/json"},
"User-Agent": []string{"redash-go"},
},
),
req.Header,
)
return httpmock.NewStringResponse(http.StatusOK, `}{`), nil
})

client, _ := redash.NewClient("https://redash.example.com", testRedashAPIKey)
_, err := client.GetQueryResultsStruct(context.Background(), 1)
assert.ErrorContains(err, "invalid character '}' looking for beginning of value")
}

func Test_GetQueryResultsStruct_Err_5xx(t *testing.T) {
assert := assert.New(t)
httpmock.Activate()
Expand Down

0 comments on commit a59faf4

Please sign in to comment.