stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
22.51k stars 1.56k forks source link

assert: handle TokenTooLong error scenario #1559

Open arjunmahishi opened 4 months ago

arjunmahishi commented 4 months ago

Summary

As pointed out in #1525, when the assertion message is too long, it gets completely truncated in the final output. This is because bufio.Scanner.Scan() has a default MaxScanTokenSize set to 65536 characters (64 * 1024). The Scan() function returns false whenever the line being scanned exceeds that max limit. This leads to the final assertion message being truncated.

Changes

This commit fixes that by manually setting the internal scan buffer size to len(message) + 1 to make sure that the above scenario never occurs.

Related issues

Fixes #1525

arjunmahishi commented 4 months ago

@dolmen @brackendawson Can you please take one last look at this? I think it's ready to be merged

arjunmahishi commented 4 months ago

@dolmen Are we good to merge?

dolmen commented 3 months ago

I'm not yet convinced that the tests provide enough coverage. I would like to see more clearly a check related to bufio boundaries.

I feel that we are testing with strings much longer than the boundary, and not just below and at the boundary. I have to dig into the code more carefully.