WaitForCmdResult try to execute a cmd until resulting output matches given predicate
( t testing.TB, command icmd.Cmd, predicate func(*icmd.Result) bool, timeout time.Duration, delay time.Duration, )
| 432 | |
| 433 | // WaitForCmdResult try to execute a cmd until resulting output matches given predicate |
| 434 | func (c *CLI) WaitForCmdResult( |
| 435 | t testing.TB, |
| 436 | command icmd.Cmd, |
| 437 | predicate func(*icmd.Result) bool, |
| 438 | timeout time.Duration, |
| 439 | delay time.Duration, |
| 440 | ) { |
| 441 | t.Helper() |
| 442 | assert.Assert(t, timeout.Nanoseconds() > delay.Nanoseconds(), "timeout must be greater than delay") |
| 443 | var res *icmd.Result |
| 444 | checkStopped := func(logt poll.LogT) poll.Result { |
| 445 | fmt.Printf("\t[%s] %s\n", t.Name(), strings.Join(command.Command, " ")) |
| 446 | res = icmd.RunCmd(command) |
| 447 | if !predicate(res) { |
| 448 | return poll.Continue("Cmd output did not match requirement: %q", res.Combined()) |
| 449 | } |
| 450 | return poll.Success() |
| 451 | } |
| 452 | poll.WaitOn(t, checkStopped, poll.WithDelay(delay), poll.WithTimeout(timeout)) |
| 453 | } |
| 454 | |
| 455 | // WaitForCondition wait for predicate to execute to true |
| 456 | func (c *CLI) WaitForCondition( |