MCPcopy
hub / github.com/basecamp/once / execInContainer

Function execInContainer

integration/docker_test.go:982–1006  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, containerName string, cmd []string)

Source from the content-addressed store, hash-verified

980}
981
982func execInContainer(t *testing.T, ctx context.Context, containerName string, cmd []string) {
983 t.Helper()
984
985 c, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
986 require.NoError(t, err)
987 defer c.Close()
988
989 execResp, err := c.ContainerExecCreate(ctx, containerName, container.ExecOptions{
990 Cmd: cmd,
991 AttachStdout: true,
992 AttachStderr: true,
993 })
994 require.NoError(t, err)
995
996 resp, err := c.ContainerExecAttach(ctx, execResp.ID, container.ExecStartOptions{})
997 require.NoError(t, err)
998 defer resp.Close()
999
1000 _, err = io.Copy(io.Discard, resp.Reader)
1001 require.NoError(t, err)
1002
1003 inspect, err := c.ContainerExecInspect(ctx, execResp.ID)
1004 require.NoError(t, err)
1005 require.Equal(t, 0, inspect.ExitCode, "exec command failed")
1006}
1007
1008func copyHookToContainer(t *testing.T, ctx context.Context, containerName, hookName string, script []byte) {
1009 t.Helper()

Callers 4

TestBackupFunction · 0.70
TestRestoreFunction · 0.70

Calls 2

EqualMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…