ktesting: support capturing log output

This is a feature of the underlying k8s.io/klog/v2/ktesting which is
useful also when using the Kubernetes ktesting.
This commit is contained in:
Patrick Ohly
2024-06-25 17:10:13 +02:00
parent 8cf93c8d83
commit fc55fecd45
3 changed files with 14 additions and 1 deletions

View File

@@ -28,3 +28,13 @@ func PerTestOutput(enabled bool) InitOption {
c.PerTestOutput = enabled
}
}
// BufferLogs controls whether log entries are captured in memory in addition
// to being printed. Off by default. Unit tests that want to verify that
// log entries are emitted as expected can turn this on and then retrieve
// the captured log through the Underlier LogSink interface.
func BufferLogs(enabled bool) InitOption {
return func(c *internal.InitConfig) {
c.BufferLogs = enabled
}
}