Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error tests #163

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ func Test_GetOrganizationStatus_OK(t *testing.T) {
}, res)
}

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

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

client, _ := redash.NewClient("https://redash.example.com", testRedashAPIKey)
_, err := client.GetOrganizationStatus(context.Background())
assert.ErrorContains(err, "GET api/organization/status failed: HTTP status code not OK: 503\nerror")
}

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

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

client, _ := redash.NewClient("https://redash.example.com", testRedashAPIKey)
_, err := client.GetOrganizationStatus(context.Background())
assert.ErrorContains(err, "Read response body failed: IO error")
}

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