diff --git a/oauth2_test.go b/oauth2_test.go index edbe03a..2ec482b 100644 --- a/oauth2_test.go +++ b/oauth2_test.go @@ -6,6 +6,7 @@ package oauth2 import ( "errors" + "fmt" "io/ioutil" "net/http" "net/http/httptest" @@ -328,3 +329,27 @@ func TestRefreshToken_RefreshTokenReplacement(t *testing.T) { t.Errorf("tokenRefresher.refresh_token = %s; want %s", tkr.refreshToken, tk.RefreshToken) } } + +func TestConfigClientWithToken(t *testing.T) { + tok := &Token{ + AccessToken: "abc123", + } + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if got, want := r.Header.Get("Authorization"), fmt.Sprintf("Bearer %s", tok.AccessToken); got != want { + t.Errorf("Authorization header = %q; want %q", got, want) + } + return + })) + defer ts.Close() + conf := newConf(ts.URL) + + c := conf.Client(NoContext, tok) + req, err := http.NewRequest("GET", ts.URL, nil) + if err != nil { + t.Error(err) + } + _, err = c.Do(req) + if err != nil { + t.Error(err) + } +}