Added client timeout because http.DefaultClient doesn't have timeout

This commit is contained in:
Junpei Tsuji
2018-05-18 12:18:09 +09:00
parent cdb4cd7c54
commit 8e67f122c0
6 changed files with 34 additions and 21 deletions

View File

@@ -37,7 +37,7 @@ func TestNew(t *testing.T) {
expected := "oauth2: cannot fetch token: 401 Unauthorized\nResponse: {\n \"error\" : \"invalid_client\",\n \"error_description\" : \"The OAuth client was invalid.\"\n}"
actual, _ := New(dummyKey)
val := actual.httpClient.Transport.(*oauth2.Transport)
val := actual.httpCli.Transport.(*oauth2.Transport)
token, err := val.Source.Token()
if token != nil {
t.Errorf("got %#v", token)
@@ -48,7 +48,7 @@ func TestNew(t *testing.T) {
// TODO Normal scenario
actual, _ = New(jsonKey)
val = actual.httpClient.Transport.(*oauth2.Transport)
val = actual.httpCli.Transport.(*oauth2.Transport)
token, err = val.Source.Token()
if err != nil {
t.Errorf("got %#v", err)
@@ -62,7 +62,7 @@ func TestNewWithClient(t *testing.T) {
httpClient := urlfetch.Client(ctx)
cli, _ := NewWithClient(dummyKey, httpClient)
tr, _ := cli.httpClient.Transport.(*oauth2.Transport)
tr, _ := cli.httpCli.Transport.(*oauth2.Transport)
if !reflect.DeepEqual(tr.Base, httpClient.Transport) {
t.Errorf("transport should be urlfetch's one")