Crate tree_fs

source ·
Expand description

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.

Example

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-fs/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

fn main() {
    let content = r#"
        override_file: false
        files:
          - path: foo.json
            content: |
              { "foo;": "bar" }
          - path: folder/bar.yaml
            content: |
              foo: bar
    "#;

    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}");
        }
    }
}

Structs

  • Represents metadata for a file in the tree.
  • Represents a file tree structure

Enums

Functions

  • Creates a file tree based on the content of a YAML file.
  • Creates a file tree based on a YAML-formatted string.

Type Aliases