TestPartialInputReader_HonoursMaxBuffer guards against pathological streams (a misbehaving provider sending megabytes of partial JSON). We refuse to grow past the configured cap.
(t *testing.T)
| 92 | // streams (a misbehaving provider sending megabytes of partial JSON). |
| 93 | // We refuse to grow past the configured cap. |
| 94 | func TestPartialInputReader_HonoursMaxBuffer(t *testing.T) { |
| 95 | // Cap chosen to fit the first object but reject the second. |
| 96 | r := NewPartialInputReader().WithMaxBuffer(20) |
| 97 | emits := 0 |
| 98 | r.OnField = func(_ PartialInputField) { emits++ } |
| 99 | |
| 100 | // 12 bytes — fits. |
| 101 | r.Feed(`{"k":"abc"}`) |
| 102 | // Push past the cap with a long second object. |
| 103 | for i := 0; i < 100; i++ { |
| 104 | r.Feed("xxxx") |
| 105 | } |
| 106 | // First object emits; subsequent oversized feeds are refused. |
| 107 | assert.Equal(t, 1, emits) |
| 108 | assert.LessOrEqual(t, len(r.Snapshot()), 20) |
| 109 | } |
| 110 | |
| 111 | // TestPartialInputReader_FedConcurrentlyDoesNotRace exercises the |
| 112 | // mutex under a small fan-in scenario. We don't expect concurrent |
nothing calls this directly
no test coverage detected