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

Function TestCompleteVolumeNames

cli/command/completion/functions_test.go:310–353  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

308}
309
310func TestCompleteVolumeNames(t *testing.T) {
311 tests := []struct {
312 doc string
313 volumes []volume.Volume
314 expOut []string
315 expDirective cobra.ShellCompDirective
316 }{
317 {
318 doc: "no results",
319 expDirective: cobra.ShellCompDirectiveNoFileComp,
320 },
321 {
322 doc: "with results",
323 volumes: []volume.Volume{
324 {Name: "volume-c"},
325 {Name: "volume-b"},
326 {Name: "volume-a"},
327 },
328 expOut: []string{"volume-c", "volume-b", "volume-a"},
329 expDirective: cobra.ShellCompDirectiveNoFileComp,
330 },
331 {
332 doc: "with error",
333 expDirective: cobra.ShellCompDirectiveError,
334 },
335 }
336
337 for _, tc := range tests {
338 t.Run(tc.doc, func(t *testing.T) {
339 comp := VolumeNames(fakeCLI{&fakeClient{
340 volumeListFunc: func(context.Context, client.VolumeListOptions) (client.VolumeListResult, error) {
341 if tc.expDirective == cobra.ShellCompDirectiveError {
342 return client.VolumeListResult{}, errors.New("some error occurred")
343 }
344 return client.VolumeListResult{Items: tc.volumes}, nil
345 },
346 }})
347
348 volumes, directives := comp(&cobra.Command{}, nil, "")
349 assert.Check(t, is.Equal(directives&tc.expDirective, tc.expDirective))
350 assert.Check(t, is.DeepEqual(volumes, tc.expOut))
351 })
352 }
353}
354
355func TestUnique(t *testing.T) {
356 base := []string{"alpha", "beta", "gamma"}

Callers

nothing calls this directly

Calls 1

VolumeNamesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…