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

Function TestVisitAll

cli-plugins/plugin/plugin_test.go:10–28  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestVisitAll(t *testing.T) {
11 root := &cobra.Command{Use: "root"}
12 sub1 := &cobra.Command{Use: "sub1"}
13 sub1sub1 := &cobra.Command{Use: "sub1sub1"}
14 sub1sub2 := &cobra.Command{Use: "sub1sub2"}
15 sub2 := &cobra.Command{Use: "sub2"}
16
17 root.AddCommand(sub1, sub2)
18 sub1.AddCommand(sub1sub1, sub1sub2)
19
20 var visited []string
21 visitAll(root, func(ccmd *cobra.Command) {
22 visited = append(visited, ccmd.Name())
23 })
24 expected := []string{"sub1sub1", "sub1sub2", "sub1", "sub2", "root"}
25 if !slices.Equal(expected, visited) {
26 t.Errorf("expected %#v, got %#v", expected, visited)
27 }
28}

Callers

nothing calls this directly

Calls 2

visitAllFunction · 0.70
NameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…