(t *testing.T)
| 112 | } |
| 113 | |
| 114 | func TestCommandOutputHonorsRootPersistentOutputJSON(t *testing.T) { |
| 115 | var stdout bytes.Buffer |
| 116 | root := &cobra.Command{} |
| 117 | root.SetOut(&stdout) |
| 118 | root.PersistentFlags().String(outputFlag, "json", "") |
| 119 | |
| 120 | out := commandOutput(root) |
| 121 | err := out.Render(func(w io.Writer) error { |
| 122 | t.Fatal("text renderer should not be called for JSON output") |
| 123 | return nil |
| 124 | }, struct { |
| 125 | Status string `json:"status"` |
| 126 | }{Status: "ok"}) |
| 127 | if err != nil { |
| 128 | t.Fatalf("Render returned error: %v", err) |
| 129 | } |
| 130 | |
| 131 | if got, want := stdout.String(), "{\"status\":\"ok\"}\n"; got != want { |
| 132 | t.Fatalf("stdout = %q, want %q", got, want) |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | func TestValidateOutputFormatRejectsInvalidValue(t *testing.T) { |
| 137 | cmd := &cobra.Command{} |
nothing calls this directly
no test coverage detected