ContainerImage.Pinniped/internal/testutil/transcript_logger.go
Ryan Richard 80153f9a80 Allow app to start despite failing to borrow the cluster signing key
- Controller and aggregated API server are allowed to run
- Keep retrying to borrow the cluster signing key in case the failure
  to get it was caused by a transient failure
- The CredentialRequest endpoint will always return an authentication
  failure as long as the cluster signing key cannot be borrowed
- Update which integration tests are skipped to reflect what should
  and should not work based on the cluster's capability under this
  new behavior
- Move CreateOrUpdateCredentialIssuerConfig() and related methods
  to their own file
- Update the CredentialIssuerConfig's Status every time we try to
  refresh the cluster signing key
2020-08-25 18:22:53 -07:00

74 lines
1.4 KiB
Go

/*
Copyright 2020 VMware, Inc.
SPDX-License-Identifier: Apache-2.0
*/
package testutil
import (
"fmt"
"sync"
"testing"
"github.com/go-logr/logr"
)
type TranscriptLogger struct {
t *testing.T
lock sync.Mutex
transcript []TranscriptLogMessage
}
var _ logr.Logger = &TranscriptLogger{}
type TranscriptLogMessage struct {
Level string
Message string
}
func NewTranscriptLogger(t *testing.T) *TranscriptLogger {
return &TranscriptLogger{t: t}
}
func (log *TranscriptLogger) Transcript() []TranscriptLogMessage {
log.lock.Lock()
defer log.lock.Unlock()
result := make([]TranscriptLogMessage, 0, len(log.transcript))
result = append(result, log.transcript...)
return result
}
func (log *TranscriptLogger) Info(msg string, keysAndValues ...interface{}) {
log.lock.Lock()
defer log.lock.Unlock()
log.transcript = append(log.transcript, TranscriptLogMessage{
Level: "info",
Message: fmt.Sprintf(msg, keysAndValues...),
})
}
func (log *TranscriptLogger) Error(_ error, msg string, _ ...interface{}) {
log.lock.Lock()
defer log.lock.Unlock()
log.transcript = append(log.transcript, TranscriptLogMessage{
Level: "error",
Message: msg,
})
}
func (*TranscriptLogger) Enabled() bool {
return true
}
func (log *TranscriptLogger) V(_ int) logr.Logger {
return log
}
func (log *TranscriptLogger) WithName(_ string) logr.Logger {
return log
}
func (log *TranscriptLogger) WithValues(_ ...interface{}) logr.Logger {
return log
}