@@ -20,6 +20,8 @@ import (
2020 "reflect"
2121 "testing"
2222
23+ commands "github.com/docker/compose/v2/cmd/compose"
24+ "github.com/spf13/cobra"
2325 flag "github.com/spf13/pflag"
2426)
2527
@@ -61,3 +63,50 @@ func TestGetFlags(t *testing.T) {
6163 })
6264 }
6365}
66+
67+ func TestCommandName (t * testing.T ) {
68+ tests := []struct {
69+ name string
70+ setupCmd func () * cobra.Command
71+ want []string
72+ }{
73+ {
74+ name : "docker compose alpha watch -> [watch, alpha]" ,
75+ setupCmd : func () * cobra.Command {
76+ dockerCmd := & cobra.Command {Use : "docker" }
77+ composeCmd := & cobra.Command {Use : commands .PluginName }
78+ alphaCmd := & cobra.Command {Use : "alpha" }
79+ watchCmd := & cobra.Command {Use : "watch" }
80+
81+ dockerCmd .AddCommand (composeCmd )
82+ composeCmd .AddCommand (alphaCmd )
83+ alphaCmd .AddCommand (watchCmd )
84+
85+ return watchCmd
86+ },
87+ want : []string {"watch" , "alpha" },
88+ },
89+ {
90+ name : "docker-compose up -> [up]" ,
91+ setupCmd : func () * cobra.Command {
92+ dockerComposeCmd := & cobra.Command {Use : commands .PluginName }
93+ upCmd := & cobra.Command {Use : "up" }
94+
95+ dockerComposeCmd .AddCommand (upCmd )
96+
97+ return upCmd
98+ },
99+ want : []string {"up" },
100+ },
101+ }
102+
103+ for _ , tt := range tests {
104+ t .Run (tt .name , func (t * testing.T ) {
105+ cmd := tt .setupCmd ()
106+ got := commandName (cmd )
107+ if ! reflect .DeepEqual (got , tt .want ) {
108+ t .Errorf ("commandName() = %v, want %v" , got , tt .want )
109+ }
110+ })
111+ }
112+ }
0 commit comments