refactor(fs/tests): group into modules
This commit is contained in:
parent
a9057a8831
commit
b32c10f080
1 changed files with 56 additions and 47 deletions
103
src/tests/fs.rs
103
src/tests/fs.rs
|
@ -4,65 +4,74 @@ use crate::fs;
|
||||||
|
|
||||||
type TestResult = Result<(), fs::Error>;
|
type TestResult = Result<(), fs::Error>;
|
||||||
|
|
||||||
#[test]
|
mod path_of {
|
||||||
fn path_of_validate_fails_path_traversal() -> TestResult {
|
use super::*;
|
||||||
let fs = fs::temp()?;
|
#[test]
|
||||||
|
fn path_of_validate_fails_path_traversal() -> TestResult {
|
||||||
|
let fs = fs::temp()?;
|
||||||
|
|
||||||
let_assert!(Err(fs::Error::PathTraversal { base, path: _path }) = fs.path_of("..".into()));
|
let_assert!(Err(fs::Error::PathTraversal { base, path: _path }) = fs.path_of("..".into()));
|
||||||
assert_eq!(base, fs.base());
|
assert_eq!(base, fs.base());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
mod file {
|
||||||
fn write_read_file_exists() -> TestResult {
|
use super::*;
|
||||||
let fs = fs::temp()?;
|
#[test]
|
||||||
let pathbuf = fs.base().join("foo");
|
fn write_read_file_exists() -> TestResult {
|
||||||
|
let fs = fs::temp()?;
|
||||||
|
let pathbuf = fs.base().join("foo");
|
||||||
|
|
||||||
let_assert!(Ok(_) = fs.file_write(&pathbuf, "content"));
|
let_assert!(Ok(_) = fs.file_write(&pathbuf, "content"));
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Ok(c) = fs.file_read_to_string(&pathbuf),
|
Ok(c) = fs.file_read_to_string(&pathbuf),
|
||||||
"file_read_to_string"
|
"file_read_to_string"
|
||||||
);
|
);
|
||||||
assert_eq!(c, "content");
|
assert_eq!(c, "content");
|
||||||
|
|
||||||
let_assert!(Ok(exists) = fs.path_exists(&pathbuf));
|
let_assert!(Ok(exists) = fs.path_exists(&pathbuf));
|
||||||
assert!(exists);
|
assert!(exists);
|
||||||
|
|
||||||
let_assert!(Ok(is_file) = fs.path_is_file(&pathbuf));
|
let_assert!(Ok(is_file) = fs.path_is_file(&pathbuf));
|
||||||
assert!(is_file);
|
assert!(is_file);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
mod dir_create {
|
||||||
fn create_dir_should_create_a_dir() -> TestResult {
|
use super::*;
|
||||||
let fs = fs::temp()?;
|
#[test]
|
||||||
let pathbuf = fs.base().join("subdir");
|
fn dir_create_should_create_a_dir() -> TestResult {
|
||||||
|
let fs = fs::temp()?;
|
||||||
|
let pathbuf = fs.base().join("subdir");
|
||||||
|
|
||||||
let_assert!(Ok(_) = fs.dir_create(&pathbuf));
|
let_assert!(Ok(_) = fs.dir_create(&pathbuf));
|
||||||
|
|
||||||
let_assert!(Ok(exists) = fs.path_exists(&pathbuf));
|
let_assert!(Ok(exists) = fs.path_exists(&pathbuf));
|
||||||
assert!(exists);
|
assert!(exists);
|
||||||
|
|
||||||
let_assert!(Ok(is_dir) = fs.path_is_dir(&pathbuf));
|
let_assert!(Ok(is_dir) = fs.path_is_dir(&pathbuf));
|
||||||
assert!(is_dir);
|
assert!(is_dir);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_dir_all_should_create_a_dir() -> TestResult {
|
fn dir_create_all_should_create_a_dir() -> TestResult {
|
||||||
let fs = fs::temp()?;
|
let fs = fs::temp()?;
|
||||||
let pathbuf = fs.base().join("subdir").join("child");
|
let pathbuf = fs.base().join("subdir").join("child");
|
||||||
|
|
||||||
let_assert!(Ok(_) = fs.dir_create_all(&pathbuf));
|
let_assert!(Ok(_) = fs.dir_create_all(&pathbuf));
|
||||||
|
|
||||||
let_assert!(Ok(exists) = fs.path_exists(&pathbuf));
|
let_assert!(Ok(exists) = fs.path_exists(&pathbuf));
|
||||||
assert!(exists, "path exists");
|
assert!(exists, "path exists");
|
||||||
|
|
||||||
let_assert!(Ok(is_dir) = fs.path_is_dir(&pathbuf));
|
let_assert!(Ok(is_dir) = fs.path_is_dir(&pathbuf));
|
||||||
assert!(is_dir, "path is a directory");
|
assert!(is_dir, "path is a directory");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue