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