(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func 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 | } |
nothing calls this directly
no test coverage detected