@@ -15,7 +15,9 @@ func TestClient_RoundTrip(t *testing.T) {
1515 t .Run ("Resource Server requires authentication" , func (t * testing.T ) {
1616 t .Run ("GET request" , func (t * testing.T ) {
1717 mux := http .NewServeMux ()
18+ invocations := 0
1819 mux .HandleFunc ("GET /resource" , func (w http.ResponseWriter , r * http.Request ) {
20+ invocations ++
1921 if r .Header .Get ("Authorization" ) != "Bearer token" {
2022 w .WriteHeader (http .StatusUnauthorized )
2123 _ , _ = w .Write ([]byte ("Unauthorized" ))
@@ -36,12 +38,15 @@ func TestClient_RoundTrip(t *testing.T) {
3638
3739 require .NoError (t , err )
3840 require .Equal (t , http .StatusOK , httpResponse .StatusCode )
41+ require .Equal (t , 1 , invocations )
3942 })
4043 t .Run ("401 Unauthorized retries HTTP request with fresh token" , func (t * testing.T ) {
4144 t .Run ("GET request" , func (t * testing.T ) {
4245 mux := http .NewServeMux ()
4346 var capturedBody []byte
47+ invocations := 0
4448 mux .HandleFunc ("GET /resource" , func (w http.ResponseWriter , r * http.Request ) {
49+ invocations ++
4550 // Reject the first token
4651 if r .Header .Get ("Authorization" ) != "Bearer token2" {
4752 w .WriteHeader (http .StatusUnauthorized )
@@ -67,6 +72,7 @@ func TestClient_RoundTrip(t *testing.T) {
6772 require .NoError (t , err )
6873 require .Equal (t , http .StatusOK , httpResponse .StatusCode )
6974 require .Empty (t , string (capturedBody ))
75+ require .Equal (t , 2 , invocations )
7076 })
7177 t .Run ("max. number of retries reached" , func (t * testing.T ) {
7278 mux := http .NewServeMux ()
0 commit comments