MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestCommandOutputHonorsInheritedOutputJSON

Function TestCommandOutputHonorsInheritedOutputJSON

cmd/output_test.go:89–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func 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
114func TestCommandOutputHonorsRootPersistentOutputJSON(t *testing.T) {
115 var stdout bytes.Buffer

Callers

nothing calls this directly

Calls 2

commandOutputFunction · 0.85
RenderMethod · 0.80

Tested by

no test coverage detected