(t *testing.T)
| 87 | } |
| 88 | |
| 89 | func TestCommandOutputHonorsInheritedOutputJSON(t *testing.T) { |
| 90 | var stdout bytes.Buffer |
| 91 | root := &cobra.Command{} |
| 92 | root.PersistentFlags().String(outputFlag, "json", "") |
| 93 | |
| 94 | cmd := &cobra.Command{} |
| 95 | cmd.SetOut(&stdout) |
| 96 | root.AddCommand(cmd) |
| 97 | |
| 98 | out := commandOutput(cmd) |
| 99 | err := out.Render(func(w io.Writer) error { |
| 100 | t.Fatal("text renderer should not be called for JSON output") |
| 101 | return nil |
| 102 | }, struct { |
| 103 | Status string `json:"status"` |
| 104 | }{Status: "ok"}) |
| 105 | if err != nil { |
| 106 | t.Fatalf("Render returned error: %v", err) |
| 107 | } |
| 108 | |
| 109 | if got, want := stdout.String(), "{\"status\":\"ok\"}\n"; got != want { |
| 110 | t.Fatalf("stdout = %q, want %q", got, want) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | func TestCommandOutputHonorsRootPersistentOutputJSON(t *testing.T) { |
| 115 | var stdout bytes.Buffer |
nothing calls this directly
no test coverage detected