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

Function TestCommandOutputHonorsRootPersistentOutputJSON

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

Source from the content-addressed store, hash-verified

112}
113
114func 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
136func TestValidateOutputFormatRejectsInvalidValue(t *testing.T) {
137 cmd := &cobra.Command{}

Callers

nothing calls this directly

Calls 2

commandOutputFunction · 0.85
RenderMethod · 0.80

Tested by

no test coverage detected