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:
		@@ -118,17 +118,18 @@ func buildDescription(explain ...interface{}) string {
 | 
				
			|||||||
// is passed in. For example, errors can be checked with ExpectNoError:
 | 
					// is passed in. For example, errors can be checked with ExpectNoError:
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//	cb := func(func(tCtx ktesting.TContext) int {
 | 
					//	cb := func(func(tCtx ktesting.TContext) int {
 | 
				
			||||||
//	   value, err := doSomething(...)
 | 
					//	    value, err := doSomething(...)
 | 
				
			||||||
//	   ktesting.ExpectNoError(tCtx, err, "something failed")
 | 
					//	    tCtx.ExpectNoError(err, "something failed")
 | 
				
			||||||
//	   return value
 | 
					//	    assert(tCtx, 42, value, "the answer")
 | 
				
			||||||
 | 
					//	    return value
 | 
				
			||||||
//	}
 | 
					//	}
 | 
				
			||||||
//	tCtx.Eventually(cb).Should(gomega.Equal(42), "should be the answer to everything")
 | 
					//	tCtx.Eventually(cb).Should(gomega.Equal(42), "should be the answer to everything")
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// If there is no value, then an error can be returned:
 | 
					// If there is no value, then an error can be returned:
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//	cb := func(func(tCtx ktesting.TContext) error {
 | 
					//	cb := func(func(tCtx ktesting.TContext) error {
 | 
				
			||||||
//	   err := doSomething(...)
 | 
					//	    err := doSomething(...)
 | 
				
			||||||
//	   return err
 | 
					//	    return err
 | 
				
			||||||
//	}
 | 
					//	}
 | 
				
			||||||
//	tCtx.Eventually(cb).Should(gomega.Succeed(), "foobar should succeed")
 | 
					//	tCtx.Eventually(cb).Should(gomega.Succeed(), "foobar should succeed")
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
@@ -143,12 +144,21 @@ func buildDescription(explain ...interface{}) string {
 | 
				
			|||||||
// anymore, use [gomega.StopTrying]:
 | 
					// anymore, use [gomega.StopTrying]:
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//	cb := func(func(tCtx ktesting.TContext) int {
 | 
					//	cb := func(func(tCtx ktesting.TContext) int {
 | 
				
			||||||
//	   value, err := doSomething(...)
 | 
					//	    value, err := doSomething(...)
 | 
				
			||||||
//	   if errors.Is(err, SomeFinalErr) {
 | 
					//	    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
 | 
				
			||||||
//	   ktesting.ExpectNoError(tCtx, err, "something failed")
 | 
					//	        // relevant information.
 | 
				
			||||||
//	   return value
 | 
					//	        //
 | 
				
			||||||
 | 
					//	        // 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
 | 
				
			||||||
//	}
 | 
					//	}
 | 
				
			||||||
//	tCtx.Eventually(cb).Should(gomega.Equal(42), "should be the answer to everything")
 | 
					//	tCtx.Eventually(cb).Should(gomega.Equal(42), "should be the answer to everything")
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
@@ -156,15 +166,15 @@ func buildDescription(explain ...interface{}) string {
 | 
				
			|||||||
// particularly useful in [Consistently] to ignore some intermittent error.
 | 
					// particularly useful in [Consistently] to ignore some intermittent error.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//	cb := func(func(tCtx ktesting.TContext) int {
 | 
					//	cb := func(func(tCtx ktesting.TContext) int {
 | 
				
			||||||
//	   value, err := doSomething(...)
 | 
					//	    value, err := doSomething(...)
 | 
				
			||||||
//	   var intermittentErr SomeIntermittentError
 | 
					//	    var intermittentErr SomeIntermittentError
 | 
				
			||||||
//	   if errors.As(err, &intermittentErr) {
 | 
					//	    if errors.As(err, &intermittentErr) {
 | 
				
			||||||
//	       gomega.TryAgainAfter(intermittentErr.RetryPeriod).Wrap(err).Now()
 | 
					//	        gomega.TryAgainAfter(intermittentErr.RetryPeriod).Wrap(err).Now()
 | 
				
			||||||
//	   }
 | 
					//	    }
 | 
				
			||||||
//	   ktesting.ExpectNoError(tCtx, err, "something failed")
 | 
					//	    ktesting.ExpectNoError(tCtx, err, "something failed")
 | 
				
			||||||
//	   return value
 | 
					//	    return value
 | 
				
			||||||
//	}
 | 
					//	 }
 | 
				
			||||||
//	tCtx.Eventually(cb).Should(gomega.Equal(42), "should be the answer to everything")
 | 
					//	 tCtx.Eventually(cb).Should(gomega.Equal(42), "should be the answer to everything")
 | 
				
			||||||
func Eventually[T any](tCtx TContext, cb func(TContext) T) gomega.AsyncAssertion {
 | 
					func Eventually[T any](tCtx TContext, cb func(TContext) T) gomega.AsyncAssertion {
 | 
				
			||||||
	tCtx.Helper()
 | 
						tCtx.Helper()
 | 
				
			||||||
	return gomega.NewWithT(tCtx).Eventually(tCtx, func(ctx context.Context) (val T, err error) {
 | 
						return gomega.NewWithT(tCtx).Eventually(tCtx, func(ctx context.Context) (val T, err error) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -83,7 +83,7 @@ type TContext interface {
 | 
				
			|||||||
	Cancel(cause string)
 | 
						Cancel(cause string)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Cleanup registers a callback that will get invoked when the test
 | 
						// 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
 | 
						// Beware of context cancellation. The following cleanup code
 | 
				
			||||||
	// will use a canceled context, which is not desirable:
 | 
						// will use a canceled context, which is not desirable:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user