func WaitOn(t TestingT, check Check, pollOps ...SettingOp)
WaitOn a condition or until a timeout. Poll by calling check and exit when check returns a done Result. To fail a test and exit polling with an error return a error result.
▹ Example
Check is a function which will be used as check for the WaitOn method.
type Check func(t LogT) Result
func Connection(network, address string) Check
Connection try to open a connection to the address on the named network. See net.Dial for a description of the network and address parameters.
func FileExists(path string) Check
FileExists looks on filesystem and check that path exists.
LogT is a logging interface that is passed to the WaitOn check function
type LogT interface { Log(args ...interface{}) Logf(format string, args ...interface{}) }
Result of a check performed by WaitOn
type Result interface { // Error indicates that the check failed and polling should stop, and the // the has failed Error() error // Done indicates that polling should stop, and the test should proceed Done() bool // Message provides the most recent state when polling has not completed Message() string }
func Compare(compare cmp.Comparison) Result
Compare values using the cmp.Comparison. If the comparison fails return a result which indicates to WaitOn that it should continue waiting. If the comparison is successful then WaitOn stops polling.
func Continue(message string, args ...interface{}) Result
Continue returns a Result that indicates to WaitOn that it should continue polling. The message text will be used as the failure message if the timeout is reached.
func Error(err error) Result
Error returns a Result that indicates to WaitOn that it should fail the test and stop polling.
func Success() Result
Success returns a Result where Done() returns true, which indicates to WaitOn that it should stop polling and exit without an error.
SettingOp is a function which accepts and modifies Settings
type SettingOp func(config *Settings)
▹ Example
func WithDelay(delay time.Duration) SettingOp
WithDelay sets the delay to wait between polls
func WithTimeout(timeout time.Duration) SettingOp
WithTimeout sets the timeout
Settings are used to configure the behaviour of WaitOn
type Settings struct { // Timeout is the maximum time to wait for the condition. Defaults to 10s. Timeout time.Duration // Delay is the time to sleep between checking the condition. Defaults to // 100ms. Delay time.Duration }
TestingT is the subset of testing.T used by WaitOn
type TestingT interface { LogT Fatalf(format string, args ...interface{}) }