8000 Add test cases to verify that error responses contain status code by AGMETEOR · Pull Request #2093 · google/go-github · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add test cases to verify that error responses contain status code #2093

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

Merged
merged 2 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ func testNewRequestAndDoFailure(t *testing.T, methodName string, client *Client,
}
}

// Test that all error response types contain the status code.
func testErrorResponseForStatusCode(t *testing.T, code int) {
t.Helper()
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/hooks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(code)
})

ctx := context.Background()
_, _, err := client.Repositories.ListHooks(ctx, "o", "r", nil)

switch e := err.(type) {
case *ErrorResponse:
case *RateLimitError:
case *AbuseRateLimitError:
if code != e.Response.StatusCode {
t.Error("Error response does not contain status code")
}
default:
t.Error("Unknown error response type")
}
}

func TestNewClient(t *testing.T) {
c := NewClient(nil)

Expand Down
8 changes: 8 additions & 0 deletions github/repos_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ func TestRepositoriesService_ListHooks_invalidOwner(t *testing.T) {
testURLParseError(t, err)
}

func TestRepositoriesService_ListHooks_403_code_no_rate_limit(t *testing.T) {
testErrorResponseForStatusCode(t, http.StatusForbidden)
}

func TestRepositoriesService_ListHooks_404_code(t *testing.T) {
testErrorResponseForStatusCode(t, http.StatusNotFound)
}

func TestRepositoriesService_GetHook(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down
0