(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestRestart(t *testing.T) { |
| 18 | for _, tc := range []struct { |
| 19 | name string |
| 20 | args []string |
| 21 | restarted []string |
| 22 | expectedOpts client.ContainerRestartOptions |
| 23 | expectedErr string |
| 24 | }{ |
| 25 | { |
| 26 | name: "without options", |
| 27 | args: []string{"container-1", "container-2"}, |
| 28 | restarted: []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 | restarted: []string{"container-1", "container-2"}, |
| 35 | }, |
| 36 | { |
| 37 | name: "with -t", |
| 38 | args: []string{"-t", "2", "container-1"}, |
| 39 | expectedOpts: client.ContainerRestartOptions{Timeout: func(to int) *int { return &to }(2)}, |
| 40 | restarted: []string{"container-1"}, |
| 41 | }, |
| 42 | { |
| 43 | name: "with --timeout", |
| 44 | args: []string{"--timeout", "2", "container-1"}, |
| 45 | expectedOpts: client.ContainerRestartOptions{Timeout: func(to int) *int { return &to }(2)}, |
| 46 | restarted: []string{"container-1"}, |
| 47 | }, |
| 48 | { |
| 49 | name: "with --time", |
| 50 | args: []string{"--time", "2", "container-1"}, |
| 51 | expectedOpts: client.ContainerRestartOptions{Timeout: func(to int) *int { return &to }(2)}, |
| 52 | restarted: []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 restarted []string |
| 62 | mutex := new(sync.Mutex) |
| 63 | |
| 64 | cli := test.NewFakeCli(&fakeClient{ |
| 65 | containerRestartFunc: func(ctx context.Context, containerID string, options client.ContainerRestartOptions) (client.ContainerRestartResult, error) { |
| 66 | assert.Check(t, is.DeepEqual(options, tc.expectedOpts)) |
| 67 | if containerID == "nosuchcontainer" { |
| 68 | return client.ContainerRestartResult{}, notFound(errors.New("Error: no such container: " + containerID)) |
| 69 | } |
| 70 | |
| 71 | // TODO(thaJeztah): consider using parallelOperation for restart, similar to "stop" and "remove" |
| 72 | mutex.Lock() |
| 73 | restarted = append(restarted, containerID) |
| 74 | mutex.Unlock() |
nothing calls this directly
no test coverage detected
searching dependent graphs…