forked from Mirrors/oauth2
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 <jbd@google.com>
This commit is contained in:
parent
191c6170f6
commit
8a57ed94ff
|
@ -13,6 +13,20 @@ func (t *tokenSource) Token() (*Token, error) {
|
||||||
return t.token, nil
|
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) {
|
func TestTransportTokenSource(t *testing.T) {
|
||||||
ts := &tokenSource{
|
ts := &tokenSource{
|
||||||
token: &Token{
|
token: &Token{
|
||||||
|
@ -28,8 +42,12 @@ func TestTransportTokenSource(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
client := http.Client{Transport: tr}
|
client := &http.Client{Transport: tr}
|
||||||
client.Get(server.URL)
|
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
|
// 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()
|
defer server.Close()
|
||||||
client := http.Client{Transport: tr}
|
client := &http.Client{Transport: tr}
|
||||||
client.Get(server.URL)
|
res, err := client.Get(server.URL)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
res.Body.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue