MCPcopy Create free account
hub / github.com/coder/envbuilder / execContainer

Function execContainer

integration/integration_test.go:2848–2868  ·  view source on GitHub ↗

execContainer executes the given command in the given container and returns the output.

(t *testing.T, containerID, command string)

Source from the content-addressed store, hash-verified

2846// execContainer executes the given command in the given container and returns
2847// the output.
2848func execContainer(t *testing.T, containerID, command string) string {
2849 t.Helper()
2850 ctx := context.Background()
2851 cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
2852 require.NoError(t, err)
2853 defer cli.Close()
2854 execConfig := container.ExecOptions{
2855 AttachStdout: true,
2856 AttachStderr: true,
2857 Cmd: []string{"/bin/sh", "-c", command},
2858 }
2859 execID, err := cli.ContainerExecCreate(ctx, containerID, execConfig)
2860 require.NoError(t, err)
2861 resp, err := cli.ContainerExecAttach(ctx, execID.ID, container.ExecAttachOptions{})
2862 require.NoError(t, err)
2863 defer resp.Close()
2864 var buf bytes.Buffer
2865 _, err = stdcopy.StdCopy(&buf, &buf, resp.Reader)
2866 require.NoError(t, err)
2867 return buf.String()
2868}
2869
2870func streamContainerLogs(t *testing.T, cli *client.Client, containerID string) (chan string, chan error) {
2871 ctx := context.Background()

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected