volume/update: require 1 argument/fix panic

This command was declaring that it requires at least 1 argument, when it
needs exactly 1 argument. This was causing the CLI to panic when the
command was invoked with no argument:

`docker volume update`

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
(cherry picked from commit daea277ee8)
Signed-off-by: Austin Vazquez <macedonv@amazon.com>
This commit is contained in:
Laura Brehm 2024-09-09 13:35:17 +01:00 committed by Austin Vazquez
parent 25adbb56af
commit 024b3c1e9b
No known key found for this signature in database
GPG Key ID: 5F5F4008442CADB8
2 changed files with 23 additions and 1 deletions

View File

@ -18,7 +18,7 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "update [OPTIONS] [VOLUME]",
Short: "Update a volume (cluster volumes only)",
Args: cli.RequiresMaxArgs(1),
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runUpdate(cmd.Context(), dockerCli, args[0], availability, cmd.Flags())
},

View File

@ -0,0 +1,22 @@
package volume
import (
"io"
"testing"
"github.com/docker/cli/internal/test"
"gotest.tools/v3/assert"
)
func TestUpdateCmd(t *testing.T) {
cmd := newUpdateCommand(
test.NewFakeCli(&fakeClient{}),
)
cmd.SetArgs([]string{})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
err := cmd.Execute()
assert.ErrorContains(t, err, "requires exactly 1 argument")
}