3 ms·
> 6. Mock out the file system Does anyone know if this is possible to do in Rust? I’ve been searching the last couple of days and I think my biggest problem is
by justwalt 7y ago
> 6. Mock out the file system
Does anyone know if this is possible to do in Rust? I’ve been searching the last couple of days and I think my biggest problem is not knowing what combination of search terms to use.
- arve0 7y agoI went to lib.rs, searched for mock and found this: https://lib.rs/crates/filesystem https://lib.rs/crates/filesystem
- justwalt 7y agoWell, I certainly knew about the filesystem crate before, but never thought to see if it offered this functionality. Thanks for this.
- steveklabnik 7y agoIf your functions take Read or Write, you can pass in something else, like memory, instead. If it doesn’t expose that the whole way up through your test layer that can be tough, of course.
- sneak 7y agoNot an answer to your question, but this is what I use for Go when I need to do this: https://github.com/spf13/afero https://github.com/spf13/afero
- novok 7y agoIn swift you make an interface / protocol that represents your filesystem API and then make an adapter that implements that API to the actual filesystem and swap with a mock when necessary. If the library you are using uses the filesystem directly, then you might need to make a similar interface adapter for the library.