From 8a57ed94ffd43444c0879fe75701732a38afc985 Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Tue, 29 Dec 2015 21:02:54 -0700 Subject: [PATCH] transport_test: added TestNilTokenSource + close res.Body per GET + TestTransportNilTokenSource added. + res.Body.Close() in tests to cut leaks and also to increase test coverage for *onEOFReader. Change-Id: I1b962b7ecbc4f6f8b5bcccc6870c025e89ad9c1a Reviewed-on: https://go-review.googlesource.com/18141 Reviewed-by: Burcu Dogan --- transport_test.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/transport_test.go b/transport_test.go index 35cb25e..9bb1383 100644 --- a/transport_test.go +++ b/transport_test.go @@ -13,6 +13,20 @@ func (t *tokenSource) Token() (*Token, error) { return t.token, nil } +func TestTransportNilTokenSource(t *testing.T) { + tr := &Transport{} + server := newMockServer(func(w http.ResponseWriter, r *http.Request) {}) + defer server.Close() + client := &http.Client{Transport: tr} + res, err := client.Get(server.URL) + if err == nil { + t.Errorf("a nil Source was passed into the transport expected an error") + } + if res != nil { + t.Errorf("expected a nil response, got %v", res) + } +} + func TestTransportTokenSource(t *testing.T) { ts := &tokenSource{ token: &Token{ @@ -28,8 +42,12 @@ func TestTransportTokenSource(t *testing.T) { } }) defer server.Close() - client := http.Client{Transport: tr} - client.Get(server.URL) + client := &http.Client{Transport: tr} + res, err := client.Get(server.URL) + if err != nil { + t.Fatal(err) + } + res.Body.Close() } // Test for case-sensitive token types, per https://github.com/golang/oauth2/issues/113 @@ -60,8 +78,12 @@ func TestTransportTokenSourceTypes(t *testing.T) { } }) defer server.Close() - client := http.Client{Transport: tr} - client.Get(server.URL) + client := &http.Client{Transport: tr} + res, err := client.Get(server.URL) + if err != nil { + t.Fatal(err) + } + res.Body.Close() } }