mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
eda311c18f
This fix moves helper functions containerIsStopped and containerIsInState to integration/internal/container, so that they could be used outside of integration/container. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package container
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/docker/docker/client"
|
|
"github.com/gotestyourself/gotestyourself/poll"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
// IsStopped verifies the container is in stopped state.
|
|
func IsStopped(ctx context.Context, client client.APIClient, containerID string) func(log poll.LogT) poll.Result {
|
|
return func(log poll.LogT) poll.Result {
|
|
inspect, err := client.ContainerInspect(ctx, containerID)
|
|
|
|
switch {
|
|
case err != nil:
|
|
return poll.Error(err)
|
|
case !inspect.State.Running:
|
|
return poll.Success()
|
|
default:
|
|
return poll.Continue("waiting for container to be stopped")
|
|
}
|
|
}
|
|
}
|
|
|
|
// IsInState verifies the container is in one of the specified state, e.g., "running", "exited", etc.
|
|
func IsInState(ctx context.Context, client client.APIClient, containerID string, state ...string) func(log poll.LogT) poll.Result {
|
|
return func(log poll.LogT) poll.Result {
|
|
inspect, err := client.ContainerInspect(ctx, containerID)
|
|
if err != nil {
|
|
return poll.Error(err)
|
|
}
|
|
for _, v := range state {
|
|
if inspect.State.Status == v {
|
|
return poll.Success()
|
|
}
|
|
}
|
|
return poll.Continue("waiting for container to be one of (%s), currently %s", strings.Join(state, ", "), inspect.State.Status)
|
|
}
|
|
}
|