2019-05-31 09:45:11 +00:00
|
|
|
package types
|
|
|
|
|
2021-09-01 13:50:18 +00:00
|
|
|
import (
|
2022-10-17 17:38:08 +00:00
|
|
|
"context"
|
2021-09-01 13:50:18 +00:00
|
|
|
"time"
|
|
|
|
)
|
2019-05-31 09:45:11 +00:00
|
|
|
|
|
|
|
type GomegaFailHandler func(message string, callerSkip ...int)
|
|
|
|
|
2022-10-17 17:38:08 +00:00
|
|
|
// A simple *testing.T interface wrapper
|
2019-05-31 09:45:11 +00:00
|
|
|
type GomegaTestingT interface {
|
2021-09-01 13:50:18 +00:00
|
|
|
Helper()
|
2019-05-31 09:45:11 +00:00
|
|
|
Fatalf(format string, args ...interface{})
|
|
|
|
}
|
|
|
|
|
2021-09-01 13:50:18 +00:00
|
|
|
// Gomega represents an object that can perform synchronous and assynchronous assertions with Gomega matchers
|
|
|
|
type Gomega interface {
|
|
|
|
Ω(actual interface{}, extra ...interface{}) Assertion
|
|
|
|
Expect(actual interface{}, extra ...interface{}) Assertion
|
|
|
|
ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Assertion
|
|
|
|
|
2023-01-30 20:05:01 +00:00
|
|
|
Eventually(actualOrCtx interface{}, args ...interface{}) AsyncAssertion
|
|
|
|
EventuallyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) AsyncAssertion
|
2021-09-01 13:50:18 +00:00
|
|
|
|
2023-01-30 20:05:01 +00:00
|
|
|
Consistently(actualOrCtx interface{}, args ...interface{}) AsyncAssertion
|
|
|
|
ConsistentlyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) AsyncAssertion
|
2021-09-01 13:50:18 +00:00
|
|
|
|
|
|
|
SetDefaultEventuallyTimeout(time.Duration)
|
|
|
|
SetDefaultEventuallyPollingInterval(time.Duration)
|
|
|
|
SetDefaultConsistentlyDuration(time.Duration)
|
|
|
|
SetDefaultConsistentlyPollingInterval(time.Duration)
|
|
|
|
}
|
|
|
|
|
2022-10-17 17:38:08 +00:00
|
|
|
// All Gomega matchers must implement the GomegaMatcher interface
|
2019-05-31 09:45:11 +00:00
|
|
|
//
|
2022-10-17 17:38:08 +00:00
|
|
|
// For details on writing custom matchers, check out: http://onsi.github.io/gomega/#adding-your-own-matchers
|
2019-05-31 09:45:11 +00:00
|
|
|
type GomegaMatcher interface {
|
|
|
|
Match(actual interface{}) (success bool, err error)
|
|
|
|
FailureMessage(actual interface{}) (message string)
|
|
|
|
NegatedFailureMessage(actual interface{}) (message string)
|
|
|
|
}
|
2021-09-01 13:50:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
GomegaMatchers that also match the OracleMatcher interface can convey information about
|
|
|
|
whether or not their result will change upon future attempts.
|
|
|
|
|
|
|
|
This allows `Eventually` and `Consistently` to short circuit if success becomes impossible.
|
|
|
|
|
|
|
|
For example, a process' exit code can never change. So, gexec's Exit matcher returns `true`
|
|
|
|
for `MatchMayChangeInTheFuture` until the process exits, at which point it returns `false` forevermore.
|
|
|
|
*/
|
|
|
|
type OracleMatcher interface {
|
|
|
|
MatchMayChangeInTheFuture(actual interface{}) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func MatchMayChangeInTheFuture(matcher GomegaMatcher, value interface{}) bool {
|
|
|
|
oracleMatcher, ok := matcher.(OracleMatcher)
|
|
|
|
if !ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return oracleMatcher.MatchMayChangeInTheFuture(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AsyncAssertions are returned by Eventually and Consistently and enable matchers to be polled repeatedly to ensure
|
|
|
|
// they are eventually satisfied
|
|
|
|
type AsyncAssertion interface {
|
|
|
|
Should(matcher GomegaMatcher, optionalDescription ...interface{}) bool
|
|
|
|
ShouldNot(matcher GomegaMatcher, optionalDescription ...interface{}) bool
|
2021-11-08 20:26:59 +00:00
|
|
|
|
|
|
|
WithOffset(offset int) AsyncAssertion
|
|
|
|
WithTimeout(interval time.Duration) AsyncAssertion
|
|
|
|
WithPolling(interval time.Duration) AsyncAssertion
|
2022-10-17 17:38:08 +00:00
|
|
|
Within(timeout time.Duration) AsyncAssertion
|
|
|
|
ProbeEvery(interval time.Duration) AsyncAssertion
|
|
|
|
WithContext(ctx context.Context) AsyncAssertion
|
|
|
|
WithArguments(argsToForward ...interface{}) AsyncAssertion
|
2023-01-30 20:05:01 +00:00
|
|
|
MustPassRepeatedly(count int) AsyncAssertion
|
2021-09-01 13:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assertions are returned by Ω and Expect and enable assertions against Gomega matchers
|
|
|
|
type Assertion interface {
|
|
|
|
Should(matcher GomegaMatcher, optionalDescription ...interface{}) bool
|
|
|
|
ShouldNot(matcher GomegaMatcher, optionalDescription ...interface{}) bool
|
|
|
|
|
|
|
|
To(matcher GomegaMatcher, optionalDescription ...interface{}) bool
|
|
|
|
ToNot(matcher GomegaMatcher, optionalDescription ...interface{}) bool
|
|
|
|
NotTo(matcher GomegaMatcher, optionalDescription ...interface{}) bool
|
2021-11-08 20:26:59 +00:00
|
|
|
|
|
|
|
WithOffset(offset int) Assertion
|
|
|
|
|
|
|
|
Error() Assertion
|
2021-09-01 13:50:18 +00:00
|
|
|
}
|