Skip to content

Commit

Permalink
Merge pull request #165 from winebarrel/add_error_tests
Browse files Browse the repository at this point in the history
Add error tests
  • Loading branch information
winebarrel authored Jun 10, 2024
2 parents 04fcd98 + 1c04bdb commit b29a945
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,40 @@ func Test_ListEvents_OK(t *testing.T) {
}, res)
}

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

httpmock.RegisterResponder(http.MethodGet, "https://redash.example.com/api/events", func(req *http.Request) (*http.Response, error) {
return httpmock.NewStringResponse(http.StatusServiceUnavailable, "error"), nil
})

client, _ := redash.NewClient("https://redash.example.com", testRedashAPIKey)
_, err := client.ListEvents(context.Background(), &redash.ListEventsInput{
Page: 1,
PageSize: 25,
})
assert.ErrorContains(err, "GET api/events failed: HTTP status code not OK: 503\nerror")
}

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

httpmock.RegisterResponder(http.MethodGet, "https://redash.example.com/api/events", func(req *http.Request) (*http.Response, error) {
return testIOErrResp, nil
})

client, _ := redash.NewClient("https://redash.example.com", testRedashAPIKey)
_, err := client.ListEvents(context.Background(), &redash.ListEventsInput{
Page: 1,
PageSize: 25,
})
assert.ErrorContains(err, "Read response body failed: IO error")
}

func Test_Event_Acc(t *testing.T) {
if !testAcc {
t.Skip()
Expand Down

0 comments on commit b29a945

Please sign in to comment.