kubernetes/test/utils/ktesting
Patrick Ohly 11dcfc6c15 ktesting: replace Begin/End with TContext.Step
Manually pairing Being with End is too error prone to be useful. It had the
advantage of keeping variables created between them visible to the following
code, but that doesn't justify using those calls.

By using a callback we can achieve a few things:

- Code using it automatically shadows the parent tCtx, thus enforcing
  that within a code block the tCtx with step is used consistently.
- The code block is clearly delineated with curly braces.
- When the code block ends, the unmodified parent tCtx is automatically
  in scope again.

Downsides:

- Extra boilerplate for the anonymous function.
  Python's `with tCtx.Step(...) as tCtx: ` would be nicer.
  As an approximation of that `for tCtx := range tCtx.Step(...)` was
  tried with `Step` returning an iterator, but that wasn't very idiomatic.
- Variables created inside the code block are not visible outside of it.

(cherry picked from commit 047682908d)
2026-01-16 08:10:36 +01:00
..
examples build: remove deprecated '// +build' tag 2025-12-18 12:16:21 +01:00
initoption ktesting: support capturing log output 2024-06-26 08:11:31 +02:00
internal ktesting: support capturing log output 2024-06-26 08:11:31 +02:00
assert.go ktesting: more flexible Eventually/Consistently 2026-01-07 14:11:33 +01:00
assert_test.go ktesting: shorter error logging in WithError 2026-01-07 14:11:33 +01:00
clientcontext.go ktesting: reimplement without interface 2026-01-05 13:45:03 +01:00
contexthelper.go ktesting: reimplement without interface 2026-01-05 13:45:03 +01:00
contexthelper_test.go ktesting: ut flake fix for CI 2024-02-26 07:26:20 -05:00
doc.go ktesting: add TContext 2024-02-11 10:51:38 +01:00
errorcontext.go ktesting: shorter error logging in WithError 2026-01-07 14:11:33 +01:00
errorcontext_test.go fix: enable and fixes rules from testifylint on test package 2024-06-30 05:44:47 +00:00
helper_test.go ktesting: reimplement without interface 2026-01-05 13:45:03 +01:00
klogcontext.go ktesting: reimplement without interface 2026-01-05 13:45:03 +01:00
ktesting.go ktesting: avoid increasing default verbosity 2026-01-09 14:54:09 +01:00
main_test.go ktesting: install signal handler on demand 2026-01-16 07:51:29 +01:00
signals.go ktesting: install signal handler on demand 2026-01-16 07:51:29 +01:00
signals_non_win.go build: remove deprecated '// +build' tag 2025-12-18 12:16:21 +01:00
signals_win.go build: remove deprecated '// +build' tag 2025-12-18 12:16:21 +01:00
stepcontext.go ktesting: replace Begin/End with TContext.Step 2026-01-16 08:10:36 +01:00
stepcontext_test.go ktesting: reimplement without interface 2026-01-05 13:45:03 +01:00
tcontext.go ktesting: install signal handler on demand 2026-01-16 07:51:29 +01:00
tcontext_test.go ktesting: add namespace support 2026-01-05 13:45:03 +01:00
withcontext.go ktesting: reimplement without interface 2026-01-05 13:45:03 +01:00