(t *testing.T)
| 536 | } |
| 537 | |
| 538 | func 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 | |
| 569 | func TestJSONErrorDetailsIncludesJoinedErrorDetails(t *testing.T) { |
| 570 | err := errors.Join( |
nothing calls this directly
no test coverage detected