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

Function TestRenderCommandErrorWritesJSONErrorToStdout

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

Source from the content-addressed store, hash-verified

277}
278
279func TestRenderCommandErrorWritesJSONErrorToStdout(t *testing.T) {
280 var stdout bytes.Buffer
281 var stderr bytes.Buffer
282 cmd := &cobra.Command{Use: "rm"}
283 cmd.SetOut(&stdout)
284 cmd.SetErr(&stderr)
285 cmd.Flags().String(outputFlag, "json", "")
286
287 renderCommandError(cmd, errors.New("failed"))
288
289 if got := stderr.String(); got != "" {
290 t.Fatalf("stderr = %q, want empty", got)
291 }
292 rendered := stdout.String()
293 got := decodeJSONErrorResponse(t, rendered)
294 if got.OK {
295 t.Fatalf("ok = true, want false")
296 }
297 if got.SchemaVersion != jsonSchemaVersion {
298 t.Fatalf("schema_version = %q, want %q", got.SchemaVersion, jsonSchemaVersion)
299 }
300 if got.Command != "rm" {
301 t.Fatalf("command = %q, want rm", got.Command)
302 }
303 if got.Error.Message != "failed" {
304 t.Fatalf("message = %q, want failed", got.Error.Message)
305 }
306 if got.Error.Code != "command_failed" {
307 t.Fatalf("code = %q, want command_failed", got.Error.Code)
308 }
309 if got.Error.Details != nil {
310 t.Fatalf("details = %+v, want nil", got.Error.Details)
311 }
312 if len(got.Warnings) != 0 {
313 t.Fatalf("warnings = %+v, want empty", got.Warnings)
314 }
315 if !strings.Contains(rendered, `"warnings":[]`) {
316 t.Fatalf("output = %q, want warnings array", rendered)
317 }
318 if strings.Contains(rendered, `"details"`) {
319 t.Fatalf("output = %q, want details omitted for generic error", rendered)
320 }
321}
322
323func TestRenderCommandErrorIncludesDeprecatedCommandWarning(t *testing.T) {
324 var stdout bytes.Buffer

Callers

nothing calls this directly

Calls 2

renderCommandErrorFunction · 0.85
decodeJSONErrorResponseFunction · 0.85

Tested by

no test coverage detected