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

Function TestVolumeCreateErrors

cli/command/volume/create_test.go:22–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestVolumeCreateErrors(t *testing.T) {
23 testCases := []struct {
24 args []string
25 flags map[string]string
26 volumeCreateFunc func(client.VolumeCreateOptions) (client.VolumeCreateResult, error)
27 expectedError string
28 }{
29 {
30 args: []string{"volumeName"},
31 flags: map[string]string{
32 "name": "volumeName",
33 },
34 expectedError: "conflicting options: cannot specify a volume-name through both --name and as a positional arg",
35 },
36 {
37 args: []string{"too", "many"},
38 expectedError: "requires at most 1 argument",
39 },
40 {
41 volumeCreateFunc: func(client.VolumeCreateOptions) (client.VolumeCreateResult, error) {
42 return client.VolumeCreateResult{}, errors.New("error creating volume")
43 },
44 expectedError: "error creating volume",
45 },
46 }
47 for _, tc := range testCases {
48 cmd := newCreateCommand(
49 test.NewFakeCli(&fakeClient{
50 volumeCreateFunc: tc.volumeCreateFunc,
51 }),
52 )
53 cmd.SetArgs(tc.args)
54 for key, value := range tc.flags {
55 assert.Check(t, cmd.Flags().Set(key, value))
56 }
57 cmd.SetOut(io.Discard)
58 cmd.SetErr(io.Discard)
59 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
60 }
61}
62
63func TestVolumeCreateWithName(t *testing.T) {
64 const name = "my-volume-name"

Callers

nothing calls this directly

Calls 5

SetArgsMethod · 0.80
newCreateCommandFunction · 0.70
SetMethod · 0.45
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…