Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
+203
View File
@@ -0,0 +1,203 @@
use std::fs;
use tree_fs::TreeBuilder;
#[test]
fn test_default_builder() {
let builder = TreeBuilder::default();
// Default builder should use a temp directory
assert!(builder.root.starts_with(std::env::temp_dir()));
// Build an empty tree
let tree = builder.create().expect("Failed to create default tree");
assert!(tree.root.exists());
assert!(tree.root.is_dir());
}
#[test]
fn test_root_folder() {
// Create a custom root in the temp directory
let custom_root = std::env::temp_dir().join("tree-fs-test-custom-root");
let _ = fs::create_dir_all(&custom_root);
let tree = TreeBuilder::default()
.root_folder(&custom_root)
.create()
.expect("Failed to create tree with custom root folder");
assert_eq!(tree.root, custom_root);
assert!(tree.root.exists());
assert!(tree.root.is_dir());
}
#[test]
fn test_add_file_methods() {
let tree = TreeBuilder::default()
.add("file1.txt", "content1") // Using add
.add_file("file2.txt", "content2") // Using add_file alias
.create()
.expect("Failed to create tree with files");
// Verify both files exist with correct content
assert!(tree.root.join("file1.txt").exists());
assert!(tree.root.join("file2.txt").exists());
assert_eq!(
fs::read_to_string(tree.root.join("file1.txt")).expect("Failed to read file1.txt"),
"content1"
);
assert_eq!(
fs::read_to_string(tree.root.join("file2.txt")).expect("Failed to read file2.txt"),
"content2"
);
}
#[test]
fn test_add_empty_file_methods() {
let tree = TreeBuilder::default()
.add_empty_file("empty1.txt") // Using add_empty_file
.add_empty("empty2.txt") // Using add_empty alias
.create()
.expect("Failed to create tree with empty files");
// Verify both files exist and are empty
assert!(tree.root.join("empty1.txt").exists());
assert!(tree.root.join("empty2.txt").exists());
assert_eq!(
fs::read_to_string(tree.root.join("empty1.txt")).expect("Failed to read empty1.txt"),
""
);
assert_eq!(
fs::read_to_string(tree.root.join("empty2.txt")).expect("Failed to read empty2.txt"),
""
);
}
#[test]
fn test_add_directory() {
let tree = TreeBuilder::default()
.add_directory("dir1")
.add_directory("dir1/subdir")
.add_file("dir1/file.txt", "content")
.create()
.expect("Failed to create tree with directories");
// Verify directories exist
assert!(tree.root.join("dir1").exists());
assert!(tree.root.join("dir1").is_dir());
assert!(tree.root.join("dir1/subdir").exists());
assert!(tree.root.join("dir1/subdir").is_dir());
// Verify file in directory
assert!(tree.root.join("dir1/file.txt").exists());
assert_eq!(
fs::read_to_string(tree.root.join("dir1/file.txt"))
.expect("Failed to read file in directory"),
"content"
);
}
#[test]
fn test_nested_structure() {
let tree = TreeBuilder::default()
.add_directory("deeply/nested/directory/structure")
.add_file("deeply/nested/file.txt", "nested file")
.add_empty_file("deeply/nested/directory/empty.txt")
.create()
.expect("Failed to create tree with nested structure");
// Verify nested structures
assert!(tree.root.join("deeply/nested/directory/structure").exists());
assert!(tree.root.join("deeply/nested/directory/structure").is_dir());
assert!(tree.root.join("deeply/nested/file.txt").exists());
assert!(tree.root.join("deeply/nested/directory/empty.txt").exists());
assert_eq!(
fs::read_to_string(tree.root.join("deeply/nested/file.txt"))
.expect("Failed to read nested file"),
"nested file"
);
}
#[test]
fn test_override_file() {
// For this test, we need a consistent root directory across multiple builders
let tree = TreeBuilder::default()
.root_folder("override-test-dir")
.add_file("test.txt", "original content")
.create()
.expect("Failed to create initial tree for override test");
let root_path = tree.root.clone();
// Verify original content
assert_eq!(
fs::read_to_string(root_path.join("test.txt"))
.expect("Failed to read original file content"),
"original content"
);
// Create a new tree with the same root but override_file set to false (default)
let _tree2 = TreeBuilder::default()
.root_folder(&root_path)
.add_file("test.txt", "new content")
.create()
.expect("Failed to create second tree for override test");
// File should still have original content since override is false by default
assert_eq!(
fs::read_to_string(root_path.join("test.txt"))
.expect("Failed to read file with override=false"),
"original content"
);
// Create a new tree with the same root but override_file set to true
let _tree3 = TreeBuilder::default()
.root_folder(&root_path)
.override_file(true)
.add_file("test.txt", "new content")
.create()
.expect("Failed to create third tree with override=true");
// File should have new content since override is true
assert_eq!(
fs::read_to_string(root_path.join("test.txt"))
.expect("Failed to read file after override=true"),
"new content"
);
}
#[test]
fn test_drop_flag() {
// Create a tree with drop = true (default)
let tree = TreeBuilder::default()
.add_file("file.txt", "content")
.create()
.expect("Failed to create tree with default drop=true");
let root_path = tree.root.clone();
assert!(root_path.exists());
// Drop the tree, root should be deleted
drop(tree);
assert!(!root_path.exists());
// Create a tree with drop = false
let tree = TreeBuilder::default()
.root_folder("no-drop-test-dir")
.drop(false)
.add_file("file.txt", "content")
.create()
.expect("Failed to create tree with drop=false");
let root_path = tree.root.clone();
assert!(root_path.exists());
// Drop the tree, root should still exist
drop(tree);
assert!(root_path.exists());
// Clean up
let _ = fs::remove_dir_all(root_path);
}
+18
View File
@@ -0,0 +1,18 @@
override_file: false
entries:
- path: foo.json
type: text_file
content: |
{ "foo": "bar" }
- path: folder/bar.yaml
type: text_file
content: |
foo: bar
- path: readonly_config.ini
type: text_file
content: |
; Sample read-only INI file
[general]
setting = value
settings:
readonly: true
+46
View File
@@ -0,0 +1,46 @@
use std::fs;
use tree_fs::{Settings, TreeBuilder};
#[test]
fn test_file_settings() {
let tree = TreeBuilder::default()
.add_file_with_settings(
"config.json",
"{\"readonly\": true}",
Settings::new().readonly(true),
)
.add_empty_file_with_settings("data.txt", Settings::new().readonly(false))
.create()
.expect("Failed to create tree with settings");
// Verify settings were applied
let readonly_perms = fs::metadata(tree.root.join("config.json"))
.expect("Failed to get metadata")
.permissions();
assert!(readonly_perms.readonly());
let writable_perms = fs::metadata(tree.root.join("data.txt"))
.expect("Failed to get metadata")
.permissions();
assert!(!writable_perms.readonly());
}
#[test]
fn test_readonly_convenience_methods() {
let tree = TreeBuilder::default()
.add_readonly_file("readonly.txt", "read-only content")
.add_readonly_empty_file("empty.txt")
.create()
.expect("Failed to create tree with readonly methods");
// Verify both files are readonly
let text_perms = fs::metadata(tree.root.join("readonly.txt"))
.expect("Failed to get metadata")
.permissions();
assert!(text_perms.readonly());
let empty_perms = fs::metadata(tree.root.join("empty.txt"))
.expect("Failed to get metadata")
.permissions();
assert!(empty_perms.readonly());
}
+180
View File
@@ -0,0 +1,180 @@
#![cfg(feature = "yaml")]
use std::fs;
use std::path::PathBuf;
#[test]
fn test_from_yaml_file() {
let yaml_path = PathBuf::from("tests/fixtures/tree.yaml");
let tree = tree_fs::from_yaml_file(&yaml_path).expect("Failed to create tree from YAML file");
// Verify that files from YAML exist
assert!(tree.root.join("foo.json").exists());
assert!(tree.root.join("folder/bar.yaml").exists());
// Verify content matches what's defined in the YAML
assert_eq!(
fs::read_to_string(tree.root.join("foo.json")).expect("Failed to read foo.json content"),
"{ \"foo\": \"bar\" }\n"
);
assert_eq!(
fs::read_to_string(tree.root.join("folder").join("bar.yaml"))
.expect("Failed to read bar.yaml content"),
"foo: bar\n"
);
}
#[test]
fn test_from_yaml_str() {
let yaml_content = r"
override_file: false
entries:
- path: foo.txt
type: text_file
content: foo
- path: folder/bar.txt
type: text_file
content: bar
";
let tree =
tree_fs::from_yaml_str(yaml_content).expect("Failed to create tree from YAML string");
// Verify that files specified in the YAML string exist
assert!(tree.root.join("foo.txt").exists());
assert!(tree.root.join("folder/bar.txt").exists());
// Verify content matches YAML definition
assert_eq!(
fs::read_to_string(tree.root.join("foo.txt")).expect("Failed to read foo.txt content"),
"foo"
);
assert_eq!(
fs::read_to_string(tree.root.join("folder/bar.txt"))
.expect("Failed to read bar.txt content"),
"bar"
);
}
#[test]
fn test_yaml_with_empty_files() {
let yaml_content = r"
entries:
- path: empty.txt
type: empty_file
- path: nested/also-empty.txt
type: empty_file
";
let tree = tree_fs::from_yaml_str(yaml_content)
.expect("Failed to create tree with empty files from YAML");
// Verify empty files exist
assert!(tree.root.join("empty.txt").exists());
assert!(tree.root.join("nested/also-empty.txt").exists());
// Verify they are indeed empty
assert_eq!(
fs::read_to_string(tree.root.join("empty.txt")).expect("Failed to read empty.txt"),
""
);
assert_eq!(
fs::read_to_string(tree.root.join("nested/also-empty.txt"))
.expect("Failed to read also-empty.txt"),
""
);
}
#[test]
fn test_yaml_with_directories() {
let yaml_content = r"
entries:
- path: empty-dir
type: directory
- path: nested/dir/structure
type: directory
";
let tree = tree_fs::from_yaml_str(yaml_content)
.expect("Failed to create tree with directories from YAML");
// Verify directories exist
assert!(tree.root.join("empty-dir").exists());
assert!(tree.root.join("empty-dir").is_dir());
assert!(tree.root.join("nested/dir/structure").exists());
assert!(tree.root.join("nested/dir/structure").is_dir());
}
#[test]
fn test_yaml_drop_behavior() {
// Test with drop: true (default)
let yaml_content = r"
entries:
- path: file.txt
type: text_file
content: test content
";
let tree =
tree_fs::from_yaml_str(yaml_content).expect("Failed to create tree with default drop=true");
let root_path = tree.root.clone();
assert!(root_path.exists());
// Drop the tree, root should be deleted
drop(tree);
assert!(!root_path.exists());
// Test with drop: false
let yaml_content = r"
drop: false
entries:
- path: file.txt
type: text_file
content: test content
";
let tree = tree_fs::from_yaml_str(yaml_content).expect("Failed to create tree with drop=false");
let root_path = tree.root.clone();
assert!(root_path.exists());
// Drop the tree, root should still exist
drop(tree);
assert!(root_path.exists());
// Clean up
let _ = fs::remove_dir_all(root_path);
}
#[test]
fn test_yaml_custom_root() {
// Create a custom root in the temp directory
let custom_root = std::env::temp_dir().join("tree-fs-yaml-test-root");
let _ = fs::create_dir_all(&custom_root);
let yaml_content = format!(
r"
root: {}
entries:
- path: custom-root-file.txt
type: text_file
content: in custom root
",
custom_root.to_string_lossy()
);
let tree =
tree_fs::from_yaml_str(&yaml_content).expect("Failed to create tree with custom root");
assert_eq!(tree.root, custom_root);
assert!(tree.root.join("custom-root-file.txt").exists());
assert_eq!(
fs::read_to_string(tree.root.join("custom-root-file.txt"))
.expect("Failed to read file in custom root"),
"in custom root"
);
// Clean up
let _ = fs::remove_dir_all(&custom_root);
}