Commit Graph

6 Commits

Author SHA1 Message Date
Kubernetes Prow Robot
1d51766c7a
Merge pull request #125698 from pohly/dra-log-output
DRA: log output
2024-06-26 12:01:03 -07:00
Patrick Ohly
fc55fecd45 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.
2024-06-26 08:11:31 +02:00
Patrick Ohly
900457c09b ktesting: improve per-test log output
format.Object adds some white space in front of the value and a type identifier
in angle brackets. Both is distracting when printing simple values and can be
avoided by picking fmt.Sprintf for those types, plus trimming the result of
format.Object.

Before:

    allocator.go:483: I0625 15:35:31.946980] Allocating one device currentClaim=    <int>: 0 totalClaims=    <int>: 1 currentRequest=    <int>: 0 totalRequestsPerClaim=    <int>: 1 currentDevice=    <int>: 0 devicesPerRequest=    <int>: 1 allDevices=    <bool>: false adminAccess=    <bool>: false

After:

    allocator.go:483: I0625 15:35:04.371441] Allocating one device currentClaim=0 totalClaims=1 currentRequest=0 totalRequestsPerClaim=1 currentDevice=0 devicesPerRequest=1 allDevices=false adminAccess=false
2024-06-25 16:00:38 +02:00
Patrick Ohly
840ef14907 ktesting: doc updates and fixes
First-in-first-out is wrong for cleanup, it's LIFO.

Updated some comments to make them more informative and fixed indention.
2024-02-25 18:13:58 +01:00
Patrick Ohly
dc6abc3ff8 ktesting: add Underlier type alias
This may help avoid importing both this ktesting and klog's ktesting.
2024-02-22 11:42:48 +01:00
Patrick Ohly
63aa261583 ktesting: add TContext
The new TContext interface combines a normal context and the testing interface,
then adds some helper methods. The context gets canceled when the test is done,
but that can also be requested earlier via Cancel.

The intended usage is to pass a single `tCtx ktesting.TContext` parameter
around in all helper functions that get called by a unit or integration test.

Logging is also more useful: Log[f] and Fatal[f] output is prefixed with
"[FATAL] ERROR: " to make it stand out more from regular log output.

If this approach turns out to be useful, it could be extended further (for
example, with a per-test timeout) and might get moved to a staging repository
to enable usage of it in other staging repositories.

To allow other implementations besides testing.T and testing.B, a custom
ktesting.TB interface gets defined with the methods expected from the
actual implementation. One such implementation can be ginkgo.GinkgoT().
2024-02-11 10:51:38 +01:00