(t *testing.T)
| 65 | } |
| 66 | |
| 67 | func TestCommandOutputHonorsOutputJSON(t *testing.T) { |
| 68 | var stdout bytes.Buffer |
| 69 | cmd := &cobra.Command{} |
| 70 | cmd.SetOut(&stdout) |
| 71 | cmd.Flags().String(outputFlag, "json", "") |
| 72 | |
| 73 | out := commandOutput(cmd) |
| 74 | err := out.Render(func(w io.Writer) error { |
| 75 | t.Fatal("text renderer should not be called for JSON output") |
| 76 | return nil |
| 77 | }, struct { |
| 78 | Status string `json:"status"` |
| 79 | }{Status: "ok"}) |
| 80 | if err != nil { |
| 81 | t.Fatalf("Render returned error: %v", err) |
| 82 | } |
| 83 | |
| 84 | if got, want := stdout.String(), "{\"status\":\"ok\"}\n"; got != want { |
| 85 | t.Fatalf("stdout = %q, want %q", got, want) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | func TestCommandOutputHonorsInheritedOutputJSON(t *testing.T) { |
| 90 | var stdout bytes.Buffer |
nothing calls this directly
no test coverage detected