ExecEnvbox runs a command in the outer container.
(t *testing.T, pool *dockertest.Pool, conf ExecConfig)
| 277 | |
| 278 | // ExecEnvbox runs a command in the outer container. |
| 279 | func ExecEnvbox(t *testing.T, pool *dockertest.Pool, conf ExecConfig) ([]byte, error) { |
| 280 | t.Helper() |
| 281 | |
| 282 | cmd, err := pool.Client.CreateExec(docker.CreateExecOptions{ |
| 283 | Cmd: conf.Cmd, |
| 284 | AttachStdout: true, |
| 285 | AttachStderr: true, |
| 286 | User: conf.User, |
| 287 | Container: conf.ContainerID, |
| 288 | }) |
| 289 | require.NoError(t, err) |
| 290 | |
| 291 | var buf bytes.Buffer |
| 292 | err = pool.Client.StartExec(cmd.ID, docker.StartExecOptions{ |
| 293 | OutputStream: &buf, |
| 294 | ErrorStream: &buf, |
| 295 | }) |
| 296 | require.NoError(t, err) |
| 297 | |
| 298 | insp, err := pool.Client.InspectExec(cmd.ID) |
| 299 | require.NoError(t, err) |
| 300 | require.Equal(t, false, insp.Running) |
| 301 | |
| 302 | if insp.ExitCode > 0 { |
| 303 | return nil, xerrors.Errorf("output(%s): exit code %d", buf.Bytes(), insp.ExitCode) |
| 304 | } |
| 305 | |
| 306 | return buf.Bytes(), nil |
| 307 | } |
| 308 | |
| 309 | func StopContainer(t *testing.T, pool *dockertest.Pool, id string, to time.Duration) { |
| 310 | t.Helper() |