You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This causes ReadAt to return a nil error when ReadAt reads less than the length of the give []byte, while the contract requires it to return a non-nil error.
A secondary bug, consequence of the problem above, is that using the fstest.TestFS(...) func of the standard library fails if the tested files have any content. This happens because it delegates testing ReadAt of the given fs.FS of the test to iotest.TestReader(...), which, in turn, makes an assertion on the condition described above.
In practical terms, I found this issue when I introduced afero and specificaly the MemMapFs to make some assertions on code I was writing that's supposed to generate and write files, and used fstest.TestFS(...) to check for the presence of the expected files I expected my code to generate.
It's an easy fix. Will soon send a PR with tests for both *mem.File and NewIOFS (i.e., use MemMapFs), and the fix.
The text was updated successfully, but these errors were encountered:
bfreis
added a commit
to bfreis/afero
that referenced
this issue
May 10, 2022
Add tests:
- ``*mem.File` implementation of `io.ReaderAt` must return non-nil error when reading less than length of give slice.
- `MemMapFs` must pass `fstest.TestFS` tests for non-empty files.
Fixes the bug.
The current implementation of
*mem.File
violates the contract defined by the Standard Library'sio.ReaderAt
interface.Specifically, according to the docs for
io.ReaderAt
:The current implementation simply delegates
ReadAt
toRead
:afero/mem/file.go
Lines 208 to 214 in 100c9a6
This causes ReadAt to return a nil error when
ReadAt
reads less than the length of the give[]byte
, while the contract requires it to return a non-nil error.A secondary bug, consequence of the problem above, is that using the
fstest.TestFS(...)
func of the standard library fails if the tested files have any content. This happens because it delegates testingReadAt
of the givenfs.FS
of the test toiotest.TestReader(...)
, which, in turn, makes an assertion on the condition described above.In practical terms, I found this issue when I introduced
afero
and specificaly theMemMapFs
to make some assertions on code I was writing that's supposed to generate and write files, and usedfstest.TestFS(...)
to check for the presence of the expected files I expected my code to generate.It's an easy fix. Will soon send a PR with tests for both
*mem.File
andNewIOFS
(i.e.,use MemMapFs
), and the fix.The text was updated successfully, but these errors were encountered: