Merge pull request #5511 from austinvazquez/cherry-pick-daea277ee839742be94e1f41d5c477f114a81273-to-25.0

[25.0 backport] volume/update: require 1 argument/fix panic
This commit is contained in:
Sebastiaan van Stijn 2024-10-08 10:49:37 +02:00 committed by GitHub
commit 315009cd65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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{ cmd := &cobra.Command{
Use: "update [OPTIONS] [VOLUME]", Use: "update [OPTIONS] [VOLUME]",
Short: "Update a volume (cluster volumes only)", Short: "Update a volume (cluster volumes only)",
Args: cli.RequiresMaxArgs(1), Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runUpdate(cmd.Context(), dockerCli, args[0], availability, cmd.Flags()) 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")
}