MCPcopy
hub / github.com/docker/compose / TestCommandName

Function TestCommandName

cmd/cmdtrace/cmd_span_test.go:68–113  ·  cmd/cmdtrace/cmd_span_test.go::TestCommandName
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestCommandName(t *testing.T) {
69 tests := []struct {
70 name string
71 setupCmd func() *cobra.Command
72 want []string
73 }{
74 {
75 name: "docker compose alpha watch -> [watch, alpha]",
76 setupCmd: func() *cobra.Command {
77 dockerCmd := &cobra.Command{Use: "docker"}
78 composeCmd := &cobra.Command{Use: commands.PluginName}
79 alphaCmd := &cobra.Command{Use: "alpha"}
80 watchCmd := &cobra.Command{Use: "watch"}
81
82 dockerCmd.AddCommand(composeCmd)
83 composeCmd.AddCommand(alphaCmd)
84 alphaCmd.AddCommand(watchCmd)
85
86 return watchCmd
87 },
88 want: []string{"watch", "alpha"},
89 },
90 {
91 name: "docker-compose up -> [up]",
92 setupCmd: func() *cobra.Command {
93 dockerComposeCmd := &cobra.Command{Use: commands.PluginName}
94 upCmd := &cobra.Command{Use: "up"}
95
96 dockerComposeCmd.AddCommand(upCmd)
97
98 return upCmd
99 },
100 want: []string{"up"},
101 },
102 }
103
104 for _, tt := range tests {
105 t.Run(tt.name, func(t *testing.T) {
106 cmd := tt.setupCmd()
107 got := commandName(cmd)
108 if !reflect.DeepEqual(got, tt.want) {
109 t.Errorf("commandName() = %v, want %v", got, tt.want)
110 }
111 })
112 }
113}

Callers

nothing calls this directly

Calls 1

commandNameFunction · 0.85

Tested by

no test coverage detected