diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index 7d521700a5..b491e24a1b 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -99,7 +99,7 @@ func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName strin if _, err := apiClient.ContainerInspect(ctx, containerIDorName); err != nil { return err } - if !execOptions.Detach { + if !options.Detach { if err := dockerCLI.In().CheckTty(execOptions.AttachStdin, execOptions.Tty); err != nil { return err } @@ -117,9 +117,9 @@ func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName strin return errors.New("exec ID empty") } - if execOptions.Detach { + if options.Detach { return apiClient.ContainerExecStart(ctx, execID, container.ExecStartOptions{ - Detach: execOptions.Detach, + Detach: options.Detach, Tty: execOptions.Tty, ConsoleSize: execOptions.ConsoleSize, }) @@ -223,7 +223,6 @@ func parseExec(execOpts ExecOptions, configFile *configfile.ConfigFile) (*contai Privileged: execOpts.Privileged, Tty: execOpts.TTY, Cmd: execOpts.Command, - Detach: execOpts.Detach, WorkingDir: execOpts.Workdir, } diff --git a/cli/command/container/exec_test.go b/cli/command/container/exec_test.go index 7ebc6b08b3..9690d091c4 100644 --- a/cli/command/container/exec_test.go +++ b/cli/command/container/exec_test.go @@ -5,6 +5,7 @@ import ( "errors" "io" "os" + "strconv" "testing" "github.com/docker/cli/cli" @@ -75,8 +76,7 @@ TWO=2 { options: withDefaultOpts(ExecOptions{Detach: true}), expected: container.ExecOptions{ - Detach: true, - Cmd: []string{"command"}, + Cmd: []string{"command"}, }, }, { @@ -86,9 +86,8 @@ TWO=2 Detach: true, }), expected: container.ExecOptions{ - Detach: true, - Tty: true, - Cmd: []string{"command"}, + Tty: true, + Cmd: []string{"command"}, }, }, { @@ -97,7 +96,6 @@ TWO=2 expected: container.ExecOptions{ Cmd: []string{"command"}, DetachKeys: "de", - Detach: true, }, }, { @@ -109,7 +107,6 @@ TWO=2 expected: container.ExecOptions{ Cmd: []string{"command"}, DetachKeys: "ab", - Detach: true, }, }, { @@ -141,10 +138,12 @@ TWO=2 }, } - for _, testcase := range testcases { - execConfig, err := parseExec(testcase.options, &testcase.configFile) - assert.NilError(t, err) - assert.Check(t, is.DeepEqual(testcase.expected, *execConfig)) + for i, testcase := range testcases { + t.Run("test "+strconv.Itoa(i+1), func(t *testing.T) { + execConfig, err := parseExec(testcase.options, &testcase.configFile) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(testcase.expected, *execConfig)) + }) } }