fs-fixture
Create filesystem fixtures fluently. Useful for testing with files and directories. Supports creating fixtures in the OS temp directory and clean up when dropped.
The library was originally adapted from https://github.com/privatenumber/fs-fixture.
Usage
use fs_fixture::{FsFixtureBuilder, FsFixtureBuilderOptions};
fn main() {
let fixture = FsFixtureBuilder::new()
.options(FsFixtureBuilderOptions {
temp_dir: PathBuf::from("/custom/temp/directory"),
..Default::default()
})
.file("file.txt", "...")
.file("nested/file.txt", "...")
.dir("dir", |d| {
d.file("file.txt", "...")
})
.symlink_file("symlink-file.txt", "file.txt")
.symlink_dir("symlink-dir", "dir")
.build()
.unwrap();
fixture.path();
fixture.path_join("nested/file.txt");
fixture.read_file("file.txt").unwrap();
fixture.write_file("file.txt", "...").unwrap();
fixture.remove_file("file.txt").unwrap();
fixture.remove().unwrap();
}
Note that the string paths only supports relative paths. Absolute paths or paths with ../ are not supported and will be internally removed and interpreted as relative paths instead. It's recommended to follow the above example convention when specifying paths.
Sponsors
License
MIT