internal: Use provided context in subsequent request
Currently the HTTP request does not set the given context. This change sets the context (if not nil) on the request. Change-Id: I4bb21636d05050a68ba70ce92f9bf9ba608fbfad Reviewed-on: https://go-review.googlesource.com/45370 Run-TryBot: Chris Broadfoot <cbro@golang.org> Reviewed-by: Jaana Burcu Dogan <jbd@google.com> Reviewed-by: Chris Broadfoot <cbro@golang.org>
This commit is contained in:
committed by
Chris Broadfoot
parent
5432cc9688
commit
626d87b993
@@ -79,3 +79,27 @@ func TestProviderAuthHeaderWorksDomain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetrieveTokenWithContexts(t *testing.T) {
|
||||
const clientID = "client-id"
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
defer ts.Close()
|
||||
|
||||
_, err := RetrieveToken(context.Background(), clientID, "", ts.URL, url.Values{})
|
||||
if err != nil {
|
||||
t.Errorf("RetrieveToken (with background context) = %v; want no error", err)
|
||||
}
|
||||
|
||||
ctx, cancelfunc := context.WithCancel(context.Background())
|
||||
|
||||
cancellingts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
cancelfunc()
|
||||
}))
|
||||
defer cancellingts.Close()
|
||||
|
||||
_, err = RetrieveToken(ctx, clientID, "", cancellingts.URL, url.Values{})
|
||||
if err == nil {
|
||||
t.Errorf("RetrieveToken (with cancelled context) = nil; want error")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user