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

Function TestVolumeCreateWithName

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

Source from the content-addressed store, hash-verified

61}
62
63func TestVolumeCreateWithName(t *testing.T) {
64 const name = "my-volume-name"
65 cli := test.NewFakeCli(&fakeClient{
66 volumeCreateFunc: func(options client.VolumeCreateOptions) (client.VolumeCreateResult, error) {
67 if options.Name != name {
68 return client.VolumeCreateResult{}, fmt.Errorf("expected name %q, got %q", name, options.Name)
69 }
70 return client.VolumeCreateResult{
71 Volume: volume.Volume{Name: options.Name},
72 }, nil
73 },
74 })
75
76 buf := cli.OutBuffer()
77 t.Run("using-flags", func(t *testing.T) {
78 cmd := newCreateCommand(cli)
79 cmd.SetOut(io.Discard)
80 cmd.SetErr(io.Discard)
81 cmd.SetArgs([]string{})
82 assert.Check(t, cmd.Flags().Set("name", name))
83 assert.NilError(t, cmd.Execute())
84 assert.Check(t, is.Equal(strings.TrimSpace(buf.String()), name))
85 })
86
87 buf.Reset()
88 t.Run("using-args", func(t *testing.T) {
89 cmd := newCreateCommand(cli)
90 cmd.SetOut(io.Discard)
91 cmd.SetErr(io.Discard)
92 cmd.SetArgs([]string{name})
93 assert.NilError(t, cmd.Execute())
94 assert.Check(t, is.Equal(strings.TrimSpace(buf.String()), name))
95 })
96
97 buf.Reset()
98 t.Run("using-both", func(t *testing.T) {
99 cmd := newCreateCommand(cli)
100 cmd.SetOut(io.Discard)
101 cmd.SetErr(io.Discard)
102 cmd.SetArgs([]string{name})
103 assert.Check(t, cmd.Flags().Set("name", name))
104 err := cmd.Execute()
105 assert.Check(t, is.Error(err, `conflicting options: cannot specify a volume-name through both --name and as a positional arg`))
106 assert.Check(t, is.Equal(strings.TrimSpace(buf.String()), ""))
107 })
108}
109
110func TestVolumeCreateWithFlags(t *testing.T) {
111 const name = "random-generated-name"

Callers

nothing calls this directly

Calls 8

OutBufferMethod · 0.95
SetArgsMethod · 0.80
newCreateCommandFunction · 0.70
StringMethod · 0.65
SetOutMethod · 0.45
SetErrMethod · 0.45
SetMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…