MCPcopy Create free account
hub / github.com/docker/cli / TestAttachInterrupt

Function TestAttachInterrupt

e2e/container/attach_test.go:35–61  ·  view source on GitHub ↗

Regression test for https://github.com/docker/cli/issues/5294

(t *testing.T)

Source from the content-addressed store, hash-verified

33
34// Regression test for https://github.com/docker/cli/issues/5294
35func TestAttachInterrupt(t *testing.T) {
36 // this is a new test, it already did not work (inside dind) when over ssh
37 // todo(laurazard): make this test work w/ dind over ssh
38 skip.If(t, strings.Contains(os.Getenv("DOCKER_HOST"), "ssh://"))
39
40 result := icmd.RunCommand("docker", "run", "-d", fixtures.AlpineImage,
41 "sh", "-c", "trap \"exit 33\" SIGINT; for i in $(seq 100); do sleep 0.1; done; exit 34")
42 result.Assert(t, icmd.Success)
43 containerID := strings.TrimSpace(result.Stdout())
44
45 // run it as such so we can signal it later
46 c := exec.Command("docker", "attach", containerID)
47 d := bytes.Buffer{}
48 c.Stdout = &d
49 c.Stderr = &d
50 _, err := pty.Start(c)
51 assert.NilError(t, err)
52
53 // have to wait a bit to give time for the command to execute/print
54 time.Sleep(500 * time.Millisecond)
55 c.Process.Signal(os.Interrupt)
56
57 _ = c.Wait()
58 // the CLI should exit with 33 (the SIGINT was forwarded to the container), and the
59 // CLI process waited for the container exit and properly captured/set the exit code
60 assert.Equal(t, c.ProcessState.ExitCode(), 33)
61}

Callers

nothing calls this directly

Calls 2

ContainsMethod · 0.80
CommandMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…