(t *testing.T, plugins []*cobra.Command, tests []staticCompletionDetails)
| 274 | } |
| 275 | |
| 276 | func checkCommand(t *testing.T, plugins []*cobra.Command, tests []staticCompletionDetails) { |
| 277 | t.Helper() |
| 278 | require.Len(t, plugins, len(tests), "Expected commands %v, got %v", tests, plugins) |
| 279 | |
| 280 | is := assert.New(t) |
| 281 | for i := range plugins { |
| 282 | pp := plugins[i] |
| 283 | tt := tests[i] |
| 284 | is.Equal(pp.Use, tt.use, "Expected Use=%q, got %q", tt.use, pp.Use) |
| 285 | |
| 286 | targs := tt.validArgs |
| 287 | pargs := pp.ValidArgs |
| 288 | is.ElementsMatch(targs, pargs) |
| 289 | |
| 290 | tflags := tt.flags |
| 291 | var pflags []string |
| 292 | pp.LocalFlags().VisitAll(func(flag *pflag.Flag) { |
| 293 | pflags = append(pflags, flag.Name) |
| 294 | if len(flag.Shorthand) > 0 && flag.Shorthand != flag.Name { |
| 295 | pflags = append(pflags, flag.Shorthand) |
| 296 | } |
| 297 | }) |
| 298 | is.ElementsMatch(tflags, pflags) |
| 299 | |
| 300 | // Check the next level |
| 301 | checkCommand(t, pp.Commands(), tt.next) |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | func TestPluginDynamicCompletion(t *testing.T) { |
| 306 | tests := []cmdTestCase{{ |
no test coverage detected
searching dependent graphs…