Add TestVolumeUnmount
This commit is contained in:
@@ -179,11 +179,45 @@ func waitForContainer(t *testing.T, cli *client.Client, ID string, timeout int64
|
||||
return rc
|
||||
}
|
||||
|
||||
// execContainer runs the specified command inside the container, returning the
|
||||
// exit code and the stdout/stderr string.
|
||||
func execContainer(t *testing.T, cli *client.Client, ID string, cmd []string) (int, string) {
|
||||
// execContainerWithExitCode runs a command in a running container, and returns the exit code
|
||||
// Note: due to a bug in Docker/Moby code, you always get an exit code of 0 if you attach to the
|
||||
// container to get output. This is why these are two separate commands.
|
||||
func execContainerWithExitCode(t *testing.T, cli *client.Client, ID string, user string, cmd []string) int {
|
||||
config := types.ExecConfig{
|
||||
User: "mqm",
|
||||
User: user,
|
||||
Privileged: false,
|
||||
Tty: false,
|
||||
AttachStdin: false,
|
||||
// Note that you still need to attach stdout/stderr, even though they're not wanted
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
Detach: false,
|
||||
Cmd: cmd,
|
||||
}
|
||||
resp, err := cli.ContainerExecCreate(context.Background(), ID, config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cli.ContainerExecStart(context.Background(), resp.ID, types.ExecStartCheck{
|
||||
Detach: false,
|
||||
Tty: false,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inspect, err := cli.ContainerExecInspect(context.Background(), resp.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return inspect.ExitCode
|
||||
}
|
||||
|
||||
// execContainerWithOutput runs a command in a running container, and returns the output from stdout/stderr
|
||||
// Note: due to a bug in Docker/Moby code, you always get an exit code of 0 if you attach to the
|
||||
// container to get output. This is why these are two separate commands.
|
||||
func execContainerWithOutput(t *testing.T, cli *client.Client, ID string, user string, cmd []string) string {
|
||||
config := types.ExecConfig{
|
||||
User: user,
|
||||
Privileged: false,
|
||||
Tty: false,
|
||||
AttachStdin: false,
|
||||
@@ -207,46 +241,19 @@ func execContainer(t *testing.T, cli *client.Client, ID string, cmd []string) (i
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inspect, err := cli.ContainerExecInspect(context.Background(), resp.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// TODO: For some reason, each line seems to start with an extra, random character
|
||||
buf, err := ioutil.ReadAll(hijack.Reader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hijack.Close()
|
||||
return inspect.ExitCode, string(buf)
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
func waitForReady(t *testing.T, cli *client.Client, ID string) {
|
||||
for {
|
||||
resp, err := cli.ContainerExecCreate(context.Background(), ID, types.ExecConfig{
|
||||
User: "mqm",
|
||||
Privileged: false,
|
||||
Tty: false,
|
||||
AttachStdin: false,
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
Detach: false,
|
||||
Cmd: []string{"chkmqready"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cli.ContainerExecStart(context.Background(), resp.ID, types.ExecStartCheck{
|
||||
Detach: false,
|
||||
Tty: false,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inspect, err := cli.ContainerExecInspect(context.Background(), resp.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if inspect.ExitCode == 0 {
|
||||
rc := execContainerWithExitCode(t, cli, ID, "mqm", []string{"chkmqready"})
|
||||
if rc == 0 {
|
||||
t.Log("MQ is ready")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user