(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func 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{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…