MCPcopy
hub / github.com/moby/moby / TestExec

Function TestExec

integration/container/exec_test.go:85–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func 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
118func TestExecResize(t *testing.T) {
119 ctx := setupTest(t)

Callers

nothing calls this directly

Calls 12

RunFunction · 0.92
WithTtyFunction · 0.92
WithWorkingDirFunction · 0.92
APIClientMethod · 0.80
CheckMethod · 0.80
EqualMethod · 0.80
setupTestFunction · 0.70
ExecCreateMethod · 0.65
ExecInspectMethod · 0.65
ExecAttachMethod · 0.65
CloseMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…