Commit Graph

14 Commits

Author SHA1 Message Date
Patrick Ohly
1d653e6185 test: use cancelation from ktesting
The return type of ktesting.NewTestContext is now a TContext. Code
which combined it WithCancel often didn't compile anymore (cannot overwrite
ktesting.TContext with context.Context). This is a good thing because all of
that code can be simplified to let ktesting handle the cancelation.
2024-03-01 07:51:22 +01:00
Kubernetes Prow Robot
e457683e6c
Merge pull request #123444 from pohly/test-context-expect-no-error
ktesting: several fixes and better unit testing
2024-02-26 20:05:40 -08:00
Rajalakshmi-Girish1
fd5019a546 ktesting: ut flake fix for CI 2024-02-26 07:26:20 -05: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
1ecd4053de ktesting: skip timing check in unit test
Extending the duration and the allowed delta in f6682370b1 was still not enough
to make the unit test run reliably in pull-kubernetes-unit.

Now it uses the original, stricter timing again, but only when run locally. In
Prow (detected by checking the "CI" env variable), the duration check is
skipped.
2024-02-24 19:26:29 +01:00
Patrick Ohly
8980b4b846 Revert "fix flaky ut in TestCause contexthelper_test"
This reverts commit f6682370b1.
2024-02-24 19:21:01 +01:00
Patrick Ohly
4cb4228522 ktesting: improve unit test coverage
In particular ExpectNoError needed testing, as it was unused so far and not
functional in its initial implementation.
2024-02-22 12:04:42 +01:00
Patrick Ohly
4ffa628ead ktesting: add missing methods to error context
Expect and ExpectNoError were not implemented and thus unintentionally
inherited from the base TContext.
2024-02-22 11:43:54 +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
fe10bfb044 ktesting: fix ExpectNoError
The error wasn't actually being checked and generating the description was
broken.
2024-02-22 11:41:51 +01:00
Paco Xu
f6682370b1 fix flaky ut in TestCause contexthelper_test 2024-02-21 19:00:41 +08: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
carlory
2315d3fed5 uncomment ktesting.AnyToString 2023-11-28 00:35:29 +08:00
Patrick Ohly
00d1459530 test/utils: extend ktesting
The upstream ktesting has to be very flexible to accommodate different ways of
using it. In Kubernetes, we can be opinionated and make certain choices, like
using klog flags, and only those.
2023-02-28 23:06:00 +01:00