(t *testing.T)
| 83 | } |
| 84 | |
| 85 | func TestExec(t *testing.T) { |
| 86 | ctx := setupTest(t) |
| 87 | apiClient := testEnv.APIClient() |
| 88 | |
| 89 | cID := container.Run(ctx, t, apiClient, container.WithTty(true), container.WithWorkingDir("/root")) |
| 90 | |
| 91 | res, err := apiClient.ExecCreate(ctx, cID, client.ExecCreateOptions{ |
| 92 | WorkingDir: "/tmp", |
| 93 | Env: []string{"FOO=BAR"}, |
| 94 | AttachStdout: true, |
| 95 | Cmd: []string{"sh", "-c", "env"}, |
| 96 | }) |
| 97 | assert.NilError(t, err) |
| 98 | |
| 99 | inspect, err := apiClient.ExecInspect(ctx, res.ID, client.ExecInspectOptions{}) |
| 100 | assert.NilError(t, err) |
| 101 | assert.Check(t, is.Equal(inspect.ID, res.ID)) |
| 102 | |
| 103 | resp, err := apiClient.ExecAttach(ctx, res.ID, client.ExecAttachOptions{}) |
| 104 | assert.NilError(t, err) |
| 105 | defer resp.Close() |
| 106 | r, err := io.ReadAll(resp.Reader) |
| 107 | assert.NilError(t, err) |
| 108 | out := string(r) |
| 109 | assert.NilError(t, err) |
| 110 | expected := "PWD=/tmp" |
| 111 | if testEnv.DaemonInfo.OSType == "windows" { |
| 112 | expected = "PWD=C:/tmp" |
| 113 | } |
| 114 | assert.Check(t, is.Contains(out, expected), "exec command not running in expected /tmp working directory") |
| 115 | assert.Check(t, is.Contains(out, "FOO=BAR"), "exec command not running with expected environment variable FOO") |
| 116 | } |
| 117 | |
| 118 | func TestExecResize(t *testing.T) { |
| 119 | ctx := setupTest(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…