From 7ab719a7d317c1939db92df95be499651e46336d Mon Sep 17 00:00:00 2001 From: Will Norris Date: Tue, 28 May 2013 18:36:14 -0700 Subject: [PATCH] add test for internal http client's Do() func --- github/github_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/github/github_test.go b/github/github_test.go index b852e31..5cc5518 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -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{},