(t *testing.T)
| 592 | } |
| 593 | |
| 594 | func TestJSONHelpAuthBypassRequiresInstalledHelpCommand(t *testing.T) { |
| 595 | root := &cobra.Command{Use: "dbxcli"} |
| 596 | root.PersistentFlags().String(outputFlag, "text", "") |
| 597 | if err := root.PersistentFlags().Set(outputFlag, "json"); err != nil { |
| 598 | t.Fatal(err) |
| 599 | } |
| 600 | |
| 601 | fakeHelp := &cobra.Command{ |
| 602 | Use: "help", |
| 603 | RunE: func(cmd *cobra.Command, args []string) error { return nil }, |
| 604 | } |
| 605 | root.AddCommand(fakeHelp) |
| 606 | if commandIsJSONHelp(fakeHelp) { |
| 607 | t.Fatal("non-annotated command named help should not bypass auth") |
| 608 | } |
| 609 | |
| 610 | jsonRoot := &cobra.Command{Use: "dbxcli"} |
| 611 | jsonRoot.PersistentFlags().String(outputFlag, "text", "") |
| 612 | if err := jsonRoot.PersistentFlags().Set(outputFlag, "json"); err != nil { |
| 613 | t.Fatal(err) |
| 614 | } |
| 615 | jsonHelp := newJSONAwareHelpCommand(jsonRoot) |
| 616 | jsonRoot.AddCommand(jsonHelp) |
| 617 | if !commandIsJSONHelp(jsonHelp) { |
| 618 | t.Fatal("installed JSON-aware help command should bypass auth for JSON help") |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | func TestJSONHelpRawArgsDetection(t *testing.T) { |
| 623 | tests := []struct { |
nothing calls this directly
no test coverage detected