mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
0de62d9bbc
A client is already created in testenv.New(), so we can just as well use that one, instead of creating a new client. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package container // import "github.com/docker/docker/integration/container"
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
containertypes "github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/client"
|
|
"github.com/docker/docker/integration/internal/container"
|
|
"gotest.tools/poll"
|
|
"gotest.tools/skip"
|
|
)
|
|
|
|
// TestHealthCheckWorkdir verifies that health-checks inherit the containers'
|
|
// working-dir.
|
|
func TestHealthCheckWorkdir(t *testing.T) {
|
|
skip.If(t, testEnv.OSType == "windows", "FIXME")
|
|
defer setupTest(t)()
|
|
ctx := context.Background()
|
|
client := testEnv.APIClient()
|
|
|
|
cID := container.Run(t, ctx, client, container.WithTty(true), container.WithWorkingDir("/foo"), func(c *container.TestContainerConfig) {
|
|
c.Config.Healthcheck = &containertypes.HealthConfig{
|
|
Test: []string{"CMD-SHELL", "if [ \"$PWD\" = \"/foo\" ]; then exit 0; else exit 1; fi;"},
|
|
Interval: 50 * time.Millisecond,
|
|
Retries: 3,
|
|
}
|
|
})
|
|
|
|
poll.WaitOn(t, pollForHealthStatus(ctx, client, cID, types.Healthy), poll.WithDelay(100*time.Millisecond))
|
|
}
|
|
|
|
func pollForHealthStatus(ctx context.Context, client client.APIClient, containerID string, healthStatus 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.Health.Status == healthStatus:
|
|
return poll.Success()
|
|
default:
|
|
return poll.Continue("waiting for container to become %s", healthStatus)
|
|
}
|
|
}
|
|
}
|