@@ -20,6 +20,8 @@ import (
20
20
"reflect"
21
21
"testing"
22
22
23
+ commands "github.com/docker/compose/v2/cmd/compose"
24
+ "github.com/spf13/cobra"
23
25
flag "github.com/spf13/pflag"
24
26
)
25
27
@@ -61,3 +63,50 @@ func TestGetFlags(t *testing.T) {
61
63
})
62
64
}
63
65
}
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