(t *testing.T)
| 426 | } |
| 427 | |
| 428 | func TestJSONHelpManifestRegistryAudit(t *testing.T) { |
| 429 | RootCmd.InitDefaultHelpCmd() |
| 430 | |
| 431 | for _, command := range publicCommandSubtree(RootCmd) { |
| 432 | path := jsonCommandManifestFor(command).Path |
| 433 | if command.Runnable() { |
| 434 | if !commandManifestRegistry[path].Known { |
| 435 | t.Errorf("runnable command %q has no command manifest registry entry", path) |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | manifest := jsonCommandManifestFor(command) |
| 440 | if manifest.InputSchema.Type != "object" { |
| 441 | t.Errorf("%s input_schema type = %q, want object", path, manifest.InputSchema.Type) |
| 442 | } |
| 443 | if manifest.InputSchema.AdditionalProperties { |
| 444 | t.Errorf("%s input_schema additionalProperties = true, want false", path) |
| 445 | } |
| 446 | if manifest.InputSchema.Required == nil { |
| 447 | t.Errorf("%s input_schema required = nil, want empty array", path) |
| 448 | } |
| 449 | if manifest.InputSchema.Properties == nil { |
| 450 | t.Errorf("%s input_schema properties = nil, want empty object", path) |
| 451 | } |
| 452 | if _, ok := manifest.InputSchema.Properties["help"]; ok { |
| 453 | t.Errorf("%s input_schema contains help flag", path) |
| 454 | } |
| 455 | if _, ok := manifest.InputSchema.Properties["output"]; ok { |
| 456 | t.Errorf("%s input_schema contains output flag", path) |
| 457 | } |
| 458 | flagNames := make(map[string]bool) |
| 459 | for _, flag := range manifest.Flags { |
| 460 | flagNames[flag.Name] = true |
| 461 | } |
| 462 | if registry := commandManifestRegistry[path]; registry.Known { |
| 463 | for name, flagMeta := range registry.Flags { |
| 464 | if !flagNames[name] { |
| 465 | t.Errorf("%s has registry metadata for unknown flag --%s", path, name) |
| 466 | } |
| 467 | for _, conflict := range flagMeta.Conflicts { |
| 468 | if !flagNames[conflict] { |
| 469 | t.Errorf("%s registry metadata for --%s conflicts with unknown flag --%s", path, name, conflict) |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | for _, flag := range manifest.Flags { |
| 475 | for _, conflict := range flag.Conflicts { |
| 476 | if !flagNames[conflict] { |
| 477 | t.Errorf("%s --%s conflicts with unknown flag --%s", path, flag.Name, conflict) |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | if manifest.SchemaRefs.SuccessSchema != commandManifestSuccessSchema { |
| 482 | t.Errorf("%s success schema = %q", path, manifest.SchemaRefs.SuccessSchema) |
| 483 | } |
| 484 | if _, err := os.Stat(filepath.Join("..", manifest.SchemaRefs.SuccessSchema)); err != nil { |
| 485 | t.Errorf("%s success schema %q is not readable: %v", path, manifest.SchemaRefs.SuccessSchema, err) |
nothing calls this directly
no test coverage detected