#file-tree #assert #folders #testing #test-files

tree-fs

Provides a convenient way to create a tree of files

1 unstable release

0.1.0 Dec 2, 2023

#735 in Filesystem

Download history 54/week @ 2024-01-05 64/week @ 2024-01-12 59/week @ 2024-01-19 48/week @ 2024-01-26 115/week @ 2024-02-02 34/week @ 2024-02-09 24/week @ 2024-02-16 111/week @ 2024-02-23 107/week @ 2024-03-01 124/week @ 2024-03-08 65/week @ 2024-03-15 22/week @ 2024-03-22 29/week @ 2024-03-29 30/week @ 2024-04-05 39/week @ 2024-04-12 13/week @ 2024-04-19

112 downloads per month
Used in 3 crates

Apache-2.0

9KB
101 lines

tree-fs

Oftentimes, testing scenarios involve interactions with the file system. tree-fs provides a convenient solution for creating file system trees tailored to the needs of your tests. This library offers:

  • An easy way to generate a tree with recursive paths.
  • Tree creation within a temporary folder.
  • The ability to create a tree using either YAML or a builder.

Usage

See usage example (here)[./examples]

From builder

use tree_fs::Tree;

fn main() {
    let res = Tree::default()
        .add("test/foo.txt", "bar")
        .add_empty("test/folder-a/folder-b/bar.txt")
        .create();

    match res {
        Ok(res) => {
            println!("created successfully in {}", res.display());
        }
        Err(err) => {
            println!("creating tree files finish with errors: {err}");
        }
    }
}

Using a YAML File

use std::path::PathBuf;

fn main() {
    let yaml_path = PathBuf::from("tree-create/tests/fixtures/tree.yaml");

    let res = tree_fs::from_yaml_file(&yaml_path);

    match res {
        Ok(res) => {
            println!("created successfully in {}", res.display());
        }
        Err(err) => {
            println!("creating tree files finish with errors: {err}");
        }
    }
}

Using a YAML String

use std::fs;

fn main() {
    let content =
        fs::read_to_string("tree-create/tests/fixtures/tree.yaml").expect("Unable to read file");

    let res = tree_fs::from_yaml_str(&content);

    match res {
        Ok(res) => {
            println!("created successfully in {}", res.display());
        }
        Err(err) => {
            println!("creating tree files finish with errors: {err}");
        }
    }
}

Dependencies

~0.7–1.6MB
~35K SLoC