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

Function TestRenderCommandErrorIncludesAdditionalContextDetails

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

Source from the content-addressed store, hash-verified

536}
537
538func TestRenderCommandErrorIncludesAdditionalContextDetails(t *testing.T) {
539 var stdout bytes.Buffer
540 var stderr bytes.Buffer
541 cmd := &cobra.Command{Use: "put"}
542 cmd.SetOut(&stdout)
543 cmd.SetErr(&stderr)
544 cmd.Flags().String(outputFlag, "json", "")
545
546 rateLimit := dropboxauth.NewRateLimitError(nil)
547 rateLimit.RetryAfter = 12
548 err := withJSONErrorDetails(
549 dropboxauth.RateLimitAPIError{RateLimitError: rateLimit},
550 operationErrorDetails("upload"),
551 urlErrorDetails("https://example.com/link"),
552 )
553 renderCommandError(cmd, err)
554
555 if got := stderr.String(); got != "" {
556 t.Fatalf("stderr = %q, want empty", got)
557 }
558 got := decodeJSONErrorResponse(t, stdout.String())
559 if got.Error.Code != jsonErrorCodeRateLimited {
560 t.Fatalf("code = %q, want %q", got.Error.Code, jsonErrorCodeRateLimited)
561 }
562 if got.Error.Details["operation"] != "upload" ||
563 got.Error.Details["url"] != "https://example.com/link" ||
564 got.Error.Details["retry_after_seconds"] != float64(12) {
565 t.Fatalf("details = %+v, want operation/url/retry_after_seconds", got.Error.Details)
566 }
567}
568
569func TestJSONErrorDetailsIncludesJoinedErrorDetails(t *testing.T) {
570 err := errors.Join(

Callers

nothing calls this directly

Calls 5

withJSONErrorDetailsFunction · 0.85
operationErrorDetailsFunction · 0.85
urlErrorDetailsFunction · 0.85
renderCommandErrorFunction · 0.85
decodeJSONErrorResponseFunction · 0.85

Tested by

no test coverage detected