Browse Source

add test for internal http client's Do() func

Will Norris 13 years ago
parent
commit
7ab719a7d3
1 changed files with 22 additions and 0 deletions
  1. +22
    -0
      github/github_test.go

+ 22
- 0
github/github_test.go View File

@ -151,6 +151,28 @@ func TestDo_httpError(t *testing.T) {
}
}
// Test handling of an error caused by the internal http client's Do()
// function. A redirect loop is pretty unlikely to occur within the GitHub
// API, but does allow us to exercise the right code path.
func TestDo_redirectLoop(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusFound)
})
req, _ := client.NewRequest("GET", "/", nil)
_, err := client.Do(req, nil)
if err == nil {
t.Error("Expected error to be returned.")
}
if err, ok := err.(*url.Error); !ok {
t.Errorf("Expected a URL error; got %#v.", err)
}
}
func TestCheckResponse(t *testing.T) {
res := &http.Response{
Request: &http.Request{},


Loading…
Cancel
Save