diff --git a/internal/token_test.go b/internal/token_test.go index a52bb81..9118d82 100644 --- a/internal/token_test.go +++ b/internal/token_test.go @@ -94,14 +94,16 @@ func TestRetrieveTokenWithContexts(t *testing.T) { t.Errorf("RetrieveToken (with background context) = %v; want no error", err) } - ctx, cancelfunc := context.WithCancel(context.Background()) - + retrieved := make(chan struct{}) cancellingts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - cancelfunc() + <-retrieved })) defer cancellingts.Close() + ctx, cancel := context.WithCancel(context.Background()) + cancel() _, err = RetrieveToken(ctx, clientID, "", cancellingts.URL, url.Values{}) + close(retrieved) if err == nil { t.Errorf("RetrieveToken (with cancelled context) = nil; want error") }