(t *testing.T)
| 476 | } |
| 477 | |
| 478 | func TestIsStreamTruncationError(t *testing.T) { |
| 479 | t.Parallel() |
| 480 | |
| 481 | tests := []struct { |
| 482 | name string |
| 483 | err error |
| 484 | expected bool |
| 485 | }{ |
| 486 | {name: "nil error", err: nil, expected: false}, |
| 487 | {name: "unexpected end of JSON input", err: errors.New("unexpected end of JSON input"), expected: true}, |
| 488 | {name: "unexpected EOF", err: errors.New("unexpected EOF"), expected: true}, |
| 489 | {name: "mixed case", err: errors.New("Unexpected EOF"), expected: true}, |
| 490 | {name: "wrapped by stream layer", err: fmt.Errorf("error receiving from stream: %w", errors.New("unexpected end of JSON input")), expected: true}, |
| 491 | // Context teardown must NOT be claimed as an upstream truncation, even |
| 492 | // if the message happens to mention EOF-ish text. |
| 493 | {name: "context canceled", err: context.Canceled, expected: false}, |
| 494 | {name: "context deadline", err: context.DeadlineExceeded, expected: false}, |
| 495 | {name: "clean EOF is not a truncation signature", err: errors.New("EOF"), expected: false}, |
| 496 | {name: "unrelated error", err: errors.New("connection refused"), expected: false}, |
| 497 | } |
| 498 | |
| 499 | for _, tt := range tests { |
| 500 | t.Run(tt.name, func(t *testing.T) { |
| 501 | t.Parallel() |
| 502 | assert.Equal(t, tt.expected, IsStreamTruncationError(tt.err), "IsStreamTruncationError(%v)", tt.err) |
| 503 | }) |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | func TestFormatError(t *testing.T) { |
| 508 | t.Parallel() |
nothing calls this directly
no test coverage detected