| 1 | package provider |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestStreamDecodeErrorQuotesPayload(t *testing.T) { |
| 10 | err := StreamDecodeError("openrouter", "DONE", errors.New("invalid character 'D' looking for beginning of value")) |
| 11 | got := err.Error() |
| 12 | if !strings.Contains(got, `payload "DONE"`) { |
| 13 | t.Errorf("error should quote the offending payload: %q", got) |
| 14 | } |
| 15 | if !strings.Contains(got, "openrouter") { |
| 16 | t.Errorf("error should name the provider: %q", got) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | func TestStreamDecodeErrorBoundsPayload(t *testing.T) { |
| 21 | long := strings.Repeat("x", streamPayloadExcerpt*3) |
| 22 | got := StreamDecodeError("p", long, errors.New("boom")).Error() |
| 23 | if len(got) > streamPayloadExcerpt*2 { |
| 24 | t.Errorf("excerpt is unbounded: %d chars", len(got)) |
| 25 | } |
| 26 | if !strings.Contains(got, "…") { |
| 27 | t.Errorf("truncated excerpt should be marked: %q", got) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func TestStreamDecodeErrorEmptyPayload(t *testing.T) { |
| 32 | got := StreamDecodeError("p", " ", errors.New("boom")).Error() |
| 33 | if !strings.Contains(got, "(empty)") { |
| 34 | t.Errorf("empty payload should say so: %q", got) |
| 35 | } |
| 36 | } |
| 37 |