4 Commits

Author SHA1 Message Date
Patrick Ohly
e5f57d2cfa ktesting: add WithoutCancel
This closes a gap compared to the context package. It's useful when combined
with Ginkgo to keep something running beyond the end of the Ginkgo BeforeEach
or It node.
2025-07-15 12:52:27 +02:00
Patrick Ohly
0b1bed1a1e ktesting: WithCancel does not cancel on test completion anymore
That WithCancel added a deferred cleanup which cancels on test termination was
unexpected. This automatic cancellation makes sense only for the initial root
TContext.
2025-07-15 12:52:27 +02:00
Patrick Ohly
f9e7b15c00 ktesting: add Run
This is useful in Go unit tests because it directly replaces the corresponding
testing.T/B.Run.
2025-02-20 14:41:06 +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