Skip to content

Commit a56d1fd

Browse files
committed
chore: address PR feedback
Signed-off-by: Matthew H. Irby <matt.irby@keyfactor.com>
1 parent 65f70ba commit a56d1fd

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

auth_providers/auth_oauth_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"os"
2626
"path/filepath"
2727
"strings"
28+
"sync/atomic"
2829
"testing"
2930

3031
"github.com/Keyfactor/keyfactor-auth-client-go/auth_providers"
@@ -572,11 +573,11 @@ func DownloadCertificate(input string, outputPath string) error {
572573
}
573574

574575
func TestCommandConfigOauth_TokenSourceIsReused(t *testing.T) {
575-
tokenRequestCount := 0
576+
var tokenRequestCount atomic.Int32
576577

577578
// Fake IdP token endpoint
578579
tokenServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
579-
tokenRequestCount++
580+
tokenRequestCount.Add(1)
580581
w.Header().Set("Content-Type", "application/json")
581582
json.NewEncoder(w).Encode(map[string]interface{}{
582583
"access_token": "shared-test-token",
@@ -605,13 +606,14 @@ func TestCommandConfigOauth_TokenSourceIsReused(t *testing.T) {
605606
if err != nil {
606607
t.Fatalf("GetHttpClient() call %d failed: %v", i+1, err)
607608
}
608-
_, err = client.Get(apiServer.URL)
609+
resp, err := client.Get(apiServer.URL)
609610
if err != nil {
610611
t.Fatalf("request %d failed: %v", i+1, err)
611612
}
613+
resp.Body.Close()
612614
}
613615

614-
if tokenRequestCount != 1 {
615-
t.Errorf("expected token endpoint to be called once, got %d — token source is not being reused across GetHttpClient() calls", tokenRequestCount)
616+
if tokenRequestCount.Load() != 1 {
617+
t.Errorf("expected token endpoint to be called once, got %d — token source is not being reused across GetHttpClient() calls", tokenRequestCount.Load())
616618
}
617619
}

0 commit comments

Comments
 (0)