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

Function TestStop

cli/command/container/stop_test.go:17–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestStop(t *testing.T) {
18 for _, tc := range []struct {
19 name string
20 args []string
21 stopped []string
22 expectedOpts client.ContainerStopOptions
23 expectedErr string
24 }{
25 {
26 name: "without options",
27 args: []string{"container-1", "container-2"},
28 stopped: []string{"container-1", "container-2"},
29 },
30 {
31 name: "with unknown container",
32 args: []string{"container-1", "nosuchcontainer", "container-2"},
33 expectedErr: "no such container",
34 stopped: []string{"container-1", "container-2"},
35 },
36 {
37 name: "with -t",
38 args: []string{"-t", "2", "container-1"},
39 expectedOpts: client.ContainerStopOptions{Timeout: func(to int) *int { return &to }(2)},
40 stopped: []string{"container-1"},
41 },
42 {
43 name: "with --timeout",
44 args: []string{"--timeout", "2", "container-1"},
45 expectedOpts: client.ContainerStopOptions{Timeout: func(to int) *int { return &to }(2)},
46 stopped: []string{"container-1"},
47 },
48 {
49 name: "with --time",
50 args: []string{"--time", "2", "container-1"},
51 expectedOpts: client.ContainerStopOptions{Timeout: func(to int) *int { return &to }(2)},
52 stopped: []string{"container-1"},
53 },
54 {
55 name: "conflicting options",
56 args: []string{"--timeout", "2", "--time", "2", "container-1"},
57 expectedErr: "conflicting options: cannot specify both --timeout and --time",
58 },
59 } {
60 t.Run(tc.name, func(t *testing.T) {
61 var stopped []string
62 mutex := new(sync.Mutex)
63
64 cli := test.NewFakeCli(&fakeClient{
65 containerStopFunc: func(ctx context.Context, containerID string, options client.ContainerStopOptions) (client.ContainerStopResult, error) {
66 assert.Check(t, is.DeepEqual(options, tc.expectedOpts))
67 if containerID == "nosuchcontainer" {
68 return client.ContainerStopResult{}, notFound(errors.New("Error: no such container: " + containerID))
69 }
70
71 // containerStopFunc is called in parallel for each container
72 // so append must be synchronized.
73 mutex.Lock()
74 stopped = append(stopped, containerID)

Callers

nothing calls this directly

Calls 5

newStopCommandFunction · 0.85
SetArgsMethod · 0.80
notFoundFunction · 0.70
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…