Skip to content

Commit fc21407

Browse files
feat(identity): enhance test logging and context handling
- Integrated klog for improved logging in identity tests - Updated `MockIdentityServer` to use `testing.TB` for broader compatibility - Added request logging in `mockIdentityServer.ServeHTTP` for better debugging
1 parent 0b4b1aa commit fc21407

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pkg/internal/cyberark/identity/advance_authentication_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import (
44
"fmt"
55
"testing"
66

7+
"k8s.io/klog/v2"
8+
"k8s.io/klog/v2/ktesting"
9+
710
"github.com/jetstack/preflight/pkg/internal/cyberark/servicediscovery"
11+
12+
_ "k8s.io/klog/v2/ktesting/init"
813
)
914

1015
func Test_IdentityAdvanceAuthentication(t *testing.T) {
@@ -97,7 +102,8 @@ func Test_IdentityAdvanceAuthentication(t *testing.T) {
97102

98103
for name, testSpec := range tests {
99104
t.Run(name, func(t *testing.T) {
100-
ctx := t.Context()
105+
logger := ktesting.NewLogger(t, ktesting.DefaultConfig)
106+
ctx := klog.NewContext(t.Context(), logger)
101107

102108
identityAPI, httpClient := MockIdentityServer(t)
103109

pkg/internal/cyberark/identity/mock.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ var (
5454
advanceAuthenticationFailureResponse string
5555
)
5656

57-
type mockIdentityServer struct{}
57+
type mockIdentityServer struct {
58+
t testing.TB
59+
}
5860

5961
// MockIdentityServer returns a URL of a mocked CyberArk identity server and an
6062
// HTTP client with the CA certs needed to connect to it..
61-
func MockIdentityServer(t *testing.T) (string, *http.Client) {
62-
mis := &mockIdentityServer{}
63+
func MockIdentityServer(t testing.TB) (string, *http.Client) {
64+
mis := &mockIdentityServer{
65+
t: t,
66+
}
6367
server := httptest.NewTLSServer(mis)
6468
t.Cleanup(server.Close)
6569
httpClient := server.Client()
@@ -68,6 +72,7 @@ func MockIdentityServer(t *testing.T) (string, *http.Client) {
6872
}
6973

7074
func (mis *mockIdentityServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
75+
mis.t.Log(r.Method, r.RequestURI)
7176
switch r.URL.String() {
7277
case "/Security/StartAuthentication":
7378
mis.handleStartAuthentication(w, r)

0 commit comments

Comments
 (0)