MCPcopy Index your code
hub / github.com/docker/cli / TestNewAttachCommandErrors

Function TestNewAttachCommandErrors

cli/command/container/attach_test.go:15–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestNewAttachCommandErrors(t *testing.T) {
16 testCases := []struct {
17 name string
18 args []string
19 expectedError string
20 containerInspectFunc func(img string) (client.ContainerInspectResult, error)
21 }{
22 {
23 name: "client-error",
24 args: []string{"5cb5bb5e4a3b"},
25 expectedError: "something went wrong",
26 containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
27 return client.ContainerInspectResult{}, errors.New("something went wrong")
28 },
29 },
30 {
31 name: "invalid-detach-keys",
32 args: []string{"--detach-keys", "shift-b", "5cb5bb5e4a3b"},
33 expectedError: "invalid detach keys (shift-b):",
34 containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
35 return client.ContainerInspectResult{}, errors.New("something went wrong")
36 },
37 },
38 {
39 name: "client-stopped",
40 args: []string{"5cb5bb5e4a3b"},
41 expectedError: "cannot attach to a stopped container",
42 containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
43 return client.ContainerInspectResult{
44 Container: container.InspectResponse{
45 State: &container.State{
46 Running: false,
47 },
48 },
49 }, nil
50 },
51 },
52 {
53 name: "client-paused",
54 args: []string{"5cb5bb5e4a3b"},
55 expectedError: "cannot attach to a paused container",
56 containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
57 return client.ContainerInspectResult{
58 Container: container.InspectResponse{
59 State: &container.State{
60 Running: true,
61 Paused: true,
62 },
63 },
64 }, nil
65 },
66 },
67 {
68 name: "client-restarting",
69 args: []string{"5cb5bb5e4a3b"},
70 expectedError: "cannot attach to a restarting container",
71 containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
72 return client.ContainerInspectResult{

Callers

nothing calls this directly

Calls 4

newAttachCommandFunction · 0.85
SetArgsMethod · 0.80
SetOutMethod · 0.45
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…