1#[cfg(test)]
2pub(crate) mod mock {
3 use std::{
4 collections::HashMap,
5 fs::File,
6 io,
7 path::{Path, PathBuf},
8 };
9 use synd_stdx::fs::FileSystem;
10
11 #[derive(Default, Clone)]
12 pub(crate) struct MockFileSystem {
13 remove_errors: HashMap<PathBuf, io::ErrorKind>,
14 }
15
16 impl MockFileSystem {
17 pub(crate) fn with_remove_errors(
18 mut self,
19 path: impl Into<PathBuf>,
20 err: io::ErrorKind,
21 ) -> Self {
22 self.remove_errors.insert(path.into(), err);
23 self
24 }
25 }
26
27 impl FileSystem for MockFileSystem {
28 fn create_dir_all<P: AsRef<Path>>(&self, _path: P) -> io::Result<()> {
29 unimplemented!()
30 }
31
32 fn create_file<P: AsRef<Path>>(&self, _path: P) -> io::Result<File> {
33 unimplemented!()
34 }
35 fn open_file<P: AsRef<Path>>(&self, _path: P) -> io::Result<File> {
36 unimplemented!()
37 }
38
39 fn remove_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
40 let path = path.as_ref();
41 match self.remove_errors.get(path) {
42 Some(err) => Err(io::Error::from(*err)),
43 None => Ok(()),
44 }
45 }
46 }
47}