MCPcopy Index your code
hub / github.com/coder/envbox / ExecEnvbox

Function ExecEnvbox

integration/integrationtest/docker.go:279–307  ·  view source on GitHub ↗

ExecEnvbox runs a command in the outer container.

(t *testing.T, pool *dockertest.Pool, conf ExecConfig)

Source from the content-addressed store, hash-verified

277
278// ExecEnvbox runs a command in the outer container.
279func 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
309func StopContainer(t *testing.T, pool *dockertest.Pool, id string, to time.Duration) {
310 t.Helper()

Callers 2

TestDockerFunction · 0.92
ExecInnerContainerFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by 1

TestDockerFunction · 0.74