execContainer executes the given command in the given container and returns the output.
(t *testing.T, containerID, command string)
| 2846 | // execContainer executes the given command in the given container and returns |
| 2847 | // the output. |
| 2848 | func 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 | |
| 2870 | func streamContainerLogs(t *testing.T, cli *client.Client, containerID string) (chan string, chan error) { |
| 2871 | ctx := context.Background() |
no test coverage detected