MCPcopy Create free account
hub / github.com/docker/cli / TestVolumeCreateWithFlags

Function TestVolumeCreateWithFlags

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

Source from the content-addressed store, hash-verified

108}
109
110func TestVolumeCreateWithFlags(t *testing.T) {
111 const name = "random-generated-name"
112 const expectedDriver = "foo-volume-driver"
113 expectedOpts := map[string]string{
114 "bar": "1",
115 "baz": "baz",
116 }
117 expectedLabels := map[string]string{
118 "lbl1": "v1",
119 "lbl2": "v2",
120 }
121
122 cli := test.NewFakeCli(&fakeClient{
123 volumeCreateFunc: func(options client.VolumeCreateOptions) (client.VolumeCreateResult, error) {
124 if options.Name != "" {
125 return client.VolumeCreateResult{}, fmt.Errorf("expected empty name, got %q", options.Name)
126 }
127 if options.Driver != expectedDriver {
128 return client.VolumeCreateResult{}, fmt.Errorf("expected driver %q, got %q", expectedDriver, options.Driver)
129 }
130 if !maps.Equal(options.DriverOpts, expectedOpts) {
131 return client.VolumeCreateResult{}, fmt.Errorf("expected drivers opts %v, got %v", expectedOpts, options.DriverOpts)
132 }
133 if !maps.Equal(options.Labels, expectedLabels) {
134 return client.VolumeCreateResult{}, fmt.Errorf("expected labels %v, got %v", expectedLabels, options.Labels)
135 }
136 return client.VolumeCreateResult{
137 Volume: volume.Volume{
138 Name: name,
139 },
140 }, nil
141 },
142 })
143
144 cmd := newCreateCommand(cli)
145 cmd.SetOut(io.Discard)
146 cmd.SetErr(io.Discard)
147 cmd.SetArgs([]string{})
148 assert.Check(t, cmd.Flags().Set("driver", expectedDriver))
149 assert.Check(t, cmd.Flags().Set("opt", "bar=1"))
150 assert.Check(t, cmd.Flags().Set("opt", "baz=baz"))
151 assert.Check(t, cmd.Flags().Set("label", "lbl1=v1"))
152 assert.Check(t, cmd.Flags().Set("label", "lbl2=v2"))
153 assert.NilError(t, cmd.Execute())
154 assert.Check(t, is.Equal(strings.TrimSpace(cli.OutBuffer().String()), name))
155}
156
157func TestVolumeCreateCluster(t *testing.T) {
158 cli := test.NewFakeCli(&fakeClient{

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…