kubernetes/test/e2e/framework/expect.go

// MakeMatcher builds a gomega.Matcher based on a single callback function.
// That function is passed the actual value that is to be checked.
// There are three possible outcomes of the check:
//   - An error is returned, which then is converted into a failure
//     by Gomega.
//   - A non-nil failure function is returned, which then is called
//     by Gomega once a failure string is needed. This is useful
//     to avoid unnecessarily preparing a failure string for intermediate
//     failures in Eventually or Consistently.
//   - Both function and error are nil, which means that the check
//     succeeded.
func MakeMatcher[T interface{}

type matcher

func (m *matcher[T]) Match(actual interface{}

func (m *matcher[T]) FailureMessage(actual interface{}

func (m matcher[T]) NegatedFailureMessage(actual interface{}

var _

// Gomega returns an interface that can be used like gomega to express
// assertions. The difference is that failed assertions are returned as an
// error:
//
//	if err := Gomega().Expect(pod.Status.Phase).To(gomega.Equal(v1.Running)); err != nil {
//	    return fmt.Errorf("test pod not running: %w", err)
//	}
//
// This error can get wrapped to provide additional context for the
// failure. The test then should use ExpectNoError to turn a non-nil error into
// a failure.
//
// When using this approach, there is no need for call offsets and extra
// descriptions for the Expect call because the call stack will be dumped when
// ExpectNoError is called and the additional description(s) can be added by
// wrapping the error.
//
// Asynchronous assertions use the framework's Poll interval and PodStart timeout
// by default.
func Gomega() GomegaInstance {}

type GomegaInstance

type Assertion

type AsyncAssertion

type gomegaInstance

var _

func (g gomegaInstance) Expect(actual interface{}

func (g gomegaInstance) Eventually(ctx context.Context, args ...interface{}

func (g gomegaInstance) Consistently(ctx context.Context, args ...interface{}

func newG() (*FailureError, gomega.Gomega) {}

type assertion

func (a assertion) Should(matcher types.GomegaMatcher) error {}

func (a assertion) ShouldNot(matcher types.GomegaMatcher) error {}

func (a assertion) To(matcher types.GomegaMatcher) error {}

func (a assertion) ToNot(matcher types.GomegaMatcher) error {}

func (a assertion) NotTo(matcher types.GomegaMatcher) error {}

type asyncAssertion

func newAsyncAssertion(ctx context.Context, args []interface{}

func (a asyncAssertion) newAsync() (*FailureError, gomega.AsyncAssertion) {}

func (a asyncAssertion) Should(matcher types.GomegaMatcher) error {}

func (a asyncAssertion) ShouldNot(matcher types.GomegaMatcher) error {}

func (a asyncAssertion) WithTimeout(timeout time.Duration) AsyncAssertion {}

func (a asyncAssertion) WithPolling(interval time.Duration) AsyncAssertion {}

type FailureError

func (f FailureError) Error() string {}

func (f FailureError) Backtrace() string {}

func (f FailureError) Is(target error) bool {}

func (f *FailureError) backtrace() {}

var ErrFailure

// ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.
//
// As in [gomega.Expect], the explain parameters can be used to provide
// additional information in case of a failure in one of these two ways:
//   - A single string is used as first line of the failure message directly.
//   - A string with additional parameters is passed through [fmt.Sprintf].
func ExpectNoError(err error, explain ...interface{}

// ExpectNoErrorWithOffset checks if "err" is set, and if so, fails assertion while logging the error at "offset" levels above its caller
// (for example, for call chain f -> g -> ExpectNoErrorWithOffset(1, ...) error would be logged for "f").
//
// As in [gomega.Expect], the explain parameters can be used to provide
// additional information in case of a failure in one of these two ways:
//   - A single string is used as first line of the failure message directly.
//   - A string with additional parameters is passed through [fmt.Sprintf].
func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}