integration-cli: remove WaitRestart(), un-export WaitForInspectResult()

- Remove `WaitRestart()` as it was no longer used
- Un-export `WaitForInspectResult()` as it was only used internally, and we want
  to reduce uses of these utilities.
- Inline `appendDocker()` into `Docker()` as it was the only place it was used,
  and the name was incorrect anyway (should've been named `prependXX`).
- Simplify `Args()`, as it was first splitting the slice (into `command` and `args`),
  only to join them again into a single slice (in `icmd.Command()`).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-23 13:06:18 +01:00
parent 598c295707
commit bc0885f364
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -42,22 +42,17 @@ func InspectCmd(t testing.TB, name string, cmdOperators ...CmdOperator) *icmd.Re
// WaitRun will wait for the specified container to be running, maximum 5 seconds.
func WaitRun(t testing.TB, name string, cmdOperators ...CmdOperator) {
WaitForInspectResult(t, name, "{{.State.Running}}", "true", 5*time.Second, cmdOperators...)
waitForInspectResult(t, name, "{{.State.Running}}", "true", 5*time.Second, cmdOperators...)
}
// WaitExited will wait for the specified container to state exit, subject
// to a maximum time limit in seconds supplied by the caller
func WaitExited(t testing.TB, name string, timeout time.Duration, cmdOperators ...CmdOperator) {
WaitForInspectResult(t, name, "{{.State.Status}}", "exited", timeout, cmdOperators...)
waitForInspectResult(t, name, "{{.State.Status}}", "exited", timeout, cmdOperators...)
}
// WaitRestart will wait for the specified container to restart once
func WaitRestart(t testing.TB, name string, timeout time.Duration, cmdOperators ...CmdOperator) {
WaitForInspectResult(t, name, "{{.RestartCount}}", "1", timeout, cmdOperators...)
}
// WaitForInspectResult waits for the specified expression to be equals to the specified expected string in the given time.
func WaitForInspectResult(t testing.TB, name, expr, expected string, timeout time.Duration, cmdOperators ...CmdOperator) {
// waitForInspectResult waits for the specified expression to be equals to the specified expected string in the given time.
func waitForInspectResult(t testing.TB, name, expr, expected string, timeout time.Duration, cmdOperators ...CmdOperator) {
after := time.After(timeout)
args := []string{"inspect", "-f", expr, name}
@ -100,7 +95,7 @@ func Docker(cmd icmd.Cmd, cmdOperators ...CmdOperator) *icmd.Result {
defer deferFn()
}
}
appendDocker(&cmd)
cmd.Command = append([]string{testEnv.DockerBinary()}, cmd.Command...)
if err := validateArgs(cmd.Command...); err != nil {
return &icmd.Result{
Error: err,
@ -148,20 +143,9 @@ func Format(format string) func(*icmd.Cmd) func() {
}
}
func appendDocker(cmd *icmd.Cmd) {
cmd.Command = append([]string{testEnv.DockerBinary()}, cmd.Command...)
}
// Args build an icmd.Cmd struct from the specified arguments
func Args(args ...string) icmd.Cmd {
switch len(args) {
case 0:
return icmd.Cmd{}
case 1:
return icmd.Command(args[0])
default:
return icmd.Command(args[0], args[1:]...)
}
// Args build an icmd.Cmd struct from the specified (command and) arguments.
func Args(commandAndArgs ...string) icmd.Cmd {
return icmd.Cmd{Command: commandAndArgs}
}
// Daemon points to the specified daemon