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.
This commit is contained in:
Patrick Ohly 2024-02-25 18:13:58 +01:00
parent 4cb4228522
commit 840ef14907
2 changed files with 31 additions and 21 deletions

View File

@ -119,7 +119,8 @@ func buildDescription(explain ...interface{}) string {
//
// cb := func(func(tCtx ktesting.TContext) int {
// value, err := doSomething(...)
// ktesting.ExpectNoError(tCtx, err, "something failed")
// tCtx.ExpectNoError(err, "something failed")
// assert(tCtx, 42, value, "the answer")
// return value
// }
// tCtx.Eventually(cb).Should(gomega.Equal(42), "should be the answer to everything")
@ -145,7 +146,16 @@ func buildDescription(explain ...interface{}) string {
// cb := func(func(tCtx ktesting.TContext) int {
// value, err := doSomething(...)
// if errors.Is(err, SomeFinalErr) {
// gomega.StopTrying("permanent failure).Wrap(err).Now()
// // This message completely replaces the normal
// // failure message and thus should include all
// // relevant information.
// //
// // github.com/onsi/gomega/format is a good way
// // to format arbitrary data. It uses indention
// // and falls back to YAML for Kubernetes API
// // structs for readability.
// gomega.StopTrying("permanent failure, last value:\n%s", format.Object(value, 1 /* indent one level */)).
// Wrap(err).Now()
// }
// ktesting.ExpectNoError(tCtx, err, "something failed")
// return value

View File

@ -83,7 +83,7 @@ type TContext interface {
Cancel(cause string)
// Cleanup registers a callback that will get invoked when the test
// has finished. Callbacks get invoked in first-in-first-out order.
// has finished. Callbacks get invoked in last-in-first-out order (LIFO).
//
// Beware of context cancellation. The following cleanup code
// will use a canceled context, which is not desirable: