News for hackers. Stuff that matters.
Re:In-Memory Filesystems in Rust by ozgrakkurt on Monday August 25, 2025 @06:27AM (#45012325)
Mocking file system or network seems counter productive.

Complicated logic can be in pure functions and not be intertwined with IO if it needs to be tested.

Mocking IO seems like it won’t really capture the problems you might encounter in reality anyway.

Re:In-Memory Filesystems in Rust by kolektiv on Monday August 25, 2025 @06:30AM (#45012355)
It's not always about mocking (in my cases it hasn't been). Sometimes it is about multiple "real" implementations - a filesystem is itself an abstraction, and a very common one, it seems like it would at least sometimes be useful to be able to leverage that more flexibly.
Re:In-Memory Filesystems in Rust by eru on Monday August 25, 2025 @06:40AM (#45012402)
I have a little system that takes a .git and mounts it as a fuse filesystem. Every commit becomes a directory with a snapshot of the project at that point in time.

You could read the whole .git in at once, and then you'd have an in-memory file-system, if you wanted to.

In any case, I agree with you: it's not about mocking.

Re:In-Memory Filesystems in Rust by kryptiskt on Monday August 25, 2025 @07:16AM (#45012595)
Some examples where it would be useful: Exposing a zip file or exe-embedded data as a filesystem, or making an FS backed by 9P, WebDAV or SFTP.
Re:In-Memory Filesystems in Rust by stingraycharles on Monday August 25, 2025 @07:20AM (#45012611)
Same like mocking databases; yes they make your tests run faster and more “pure”, but you’re suddenly not really testing reality anymore.
Re:In-Memory Filesystems in Rust by boomlinde on Monday August 25, 2025 @08:55AM (#45013331)
Sure, but they're not mutually exclusive approaches. Having tests that run in a couple of seconds thanks to low I/O and cheap scaffolding setup/teardown can be a valuable addition to slower, comprehensive system and integration test suites.
Re:In-Memory Filesystems in Rust by actionfromafar on Monday August 25, 2025 @10:09AM (#45014041)
And you can spot differences between your understanding of reality (test mockups) and how it behaves on the real filesystem. (In this case.)
Re:In-Memory Filesystems in Rust by Arch-TK on Monday August 25, 2025 @08:30AM (#45013137)
Fault injection is much easier if you can mock IO. And you aren't really testing your software if you're not injecting faults.
Re:In-Memory Filesystems in Rust by ozgrakkurt on Tuesday August 26, 2025 @11:50PM (#45035276)
My point is, you can give gibberish data to a processing function if it just takes in-memory data instead of being parameterized by “IO”.

If you parameterize everything by IO then you have to mock the IO

Re:In-Memory Filesystems in Rust by Arch-TK on Thursday August 28, 2025 @10:47AM (#45052874)
It's not just about gibberish data. It's read failures, write failures, open failures, for a variety of reasons including permission errors, disk errors, space errors, etc.

You basically want to test your code does something sensical with either every possible combination of errors, or with some random subset of combinations of errors. This can be automated and can verify the behaviour of your program in the edge cases. It's actually not usually that helpful to only test "we read corrupt garbage from the file" which is the thing you're describing here.