plog.TestLogger returns a buffer that holds the logs

# Conflicts:
#	internal/controller/apicerts/certs_expirer_test.go
#	internal/plog/plog_test.go
#	internal/plog/testing.go
#	pkg/oidcclient/login_test.go
This commit is contained in:
Joshua Casey
2024-11-01 09:18:47 -05:00
parent a67af9455b
commit dd42f35db0
3 changed files with 12 additions and 13 deletions

View File

@@ -2555,7 +2555,7 @@ func TestController(t *testing.T) {
require.Len(t, actualIDP.Status.Conditions, countExpectedConditions)
require.Equal(t, tt.wantResultingUpstreams[i], *actualIDP)
}
testutil.RequireLogLines(t, tt.wantLogs, &log)
testutil.RequireLogLines(t, tt.wantLogs, log)
// This needs to happen after the expected condition LastTransitionTime has been updated.
wantActions := make([]coretesting.Action, 3+len(tt.wantResultingUpstreams))

View File

@@ -3941,8 +3941,7 @@ func TestAuthorizationEndpoint(t *testing.T) { //nolint:gocyclo
if len(test.wantDownstreamAdditionalClaims) > 0 {
require.True(t, oidcIDPsCount > 0, "wantDownstreamAdditionalClaims requires at least one OIDC IDP")
}
var auditLog bytes.Buffer
auditLogger := plog.TestLogger(t, &auditLog)
auditLogger, auditLog := plog.TestLogger(t)
subject := NewHandler(
downstreamIssuer,
idps,
@@ -3951,7 +3950,7 @@ func TestAuthorizationEndpoint(t *testing.T) { //nolint:gocyclo
test.stateEncoder, test.cookieEncoder,
auditLogger,
)
runOneTestCase(t, test, subject, kubeOauthStore, supervisorClient, kubeClient, secretsClient, &auditLog)
runOneTestCase(t, test, subject, kubeOauthStore, supervisorClient, kubeClient, secretsClient, auditLog)
})
}
@@ -3969,8 +3968,7 @@ func TestAuthorizationEndpoint(t *testing.T) { //nolint:gocyclo
oauthHelperWithRealStorage, kubeOauthStore := createOauthHelperWithRealStorage(secretsClient, oidcClientsClient)
oauthHelperWithNullStorage, _ := createOauthHelperWithNullStorage(secretsClient, oidcClientsClient)
idpLister := test.idps.BuildFederationDomainIdentityProvidersListerFinder()
var auditLog bytes.Buffer
auditLogger := plog.TestLogger(t, &auditLog)
auditLogger, auditLog := plog.TestLogger(t)
subject := NewHandler(
downstreamIssuer,
idpLister,
@@ -3980,7 +3978,7 @@ func TestAuthorizationEndpoint(t *testing.T) { //nolint:gocyclo
auditLogger,
)
runOneTestCase(t, test, subject, kubeOauthStore, supervisorClient, kubeClient, secretsClient, &auditLog)
runOneTestCase(t, test, subject, kubeOauthStore, supervisorClient, kubeClient, secretsClient, auditLog)
// Call the idpLister's setter to change the upstream IDP settings.
newProviderSettings := oidctestutil.NewTestUpstreamOIDCIdentityProviderBuilder().
@@ -4023,7 +4021,7 @@ func TestAuthorizationEndpoint(t *testing.T) { //nolint:gocyclo
// modified expectations. This should ensure that the implementation is using the in-memory cache
// of upstream IDP settings appropriately in terms of always getting the values from the cache
// on every request.
runOneTestCase(t, test, subject, kubeOauthStore, supervisorClient, kubeClient, secretsClient, &auditLog)
runOneTestCase(t, test, subject, kubeOauthStore, supervisorClient, kubeClient, secretsClient, auditLog)
})
}

View File

@@ -4,6 +4,7 @@
package plog
import (
"bytes"
"fmt"
"runtime"
"strings"
@@ -355,14 +356,14 @@ func TestPlog(t *testing.T) {
`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
subjectLogger, log := TestLogger(t)
tt.run(subjectLogger)
testLogger, log := TestLogger(t)
test.run(testLogger)
require.Equal(t, strings.TrimSpace(tt.want), strings.TrimSpace(log.String()))
require.Equal(t, strings.TrimSpace(test.want), strings.TrimSpace(log.String()))
})
}
}