refactor(fs/tests): group into modules

This commit is contained in:
Paul Campbell 2024-04-28 15:01:29 +01:00
parent a9057a8831
commit b32c10f080

View file

@ -4,18 +4,23 @@ 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::*;
#[test]
fn path_of_validate_fails_path_traversal() -> TestResult {
let fs = fs::temp()?; 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::*;
#[test]
fn write_read_file_exists() -> TestResult {
let fs = fs::temp()?; let fs = fs::temp()?;
let pathbuf = fs.base().join("foo"); let pathbuf = fs.base().join("foo");
@ -33,10 +38,13 @@ fn write_read_file_exists() -> TestResult {
assert!(is_file); assert!(is_file);
Ok(()) Ok(())
}
} }
#[test] mod dir_create {
fn create_dir_should_create_a_dir() -> TestResult { use super::*;
#[test]
fn dir_create_should_create_a_dir() -> TestResult {
let fs = fs::temp()?; let fs = fs::temp()?;
let pathbuf = fs.base().join("subdir"); let pathbuf = fs.base().join("subdir");
@ -49,10 +57,10 @@ fn create_dir_should_create_a_dir() -> TestResult {
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");
@ -65,4 +73,5 @@ fn create_dir_all_should_create_a_dir() -> TestResult {
assert!(is_dir, "path is a directory"); assert!(is_dir, "path is a directory");
Ok(()) Ok(())
}
} }