tree-type 0.4.5

Rust macros for creating type-safe filesystem tree structures
Documentation
#![allow(deprecated)]

use std::fs;
use tree_type::tree_type;

#[test]
#[cfg(unix)]
fn test_file_symlink_created_by_setup() {
    tree_type! {
        TestRoot {
            #[default("main content")]
            main("main.txt"),
            #[symlink(main)]
            backup("backup.txt")
        }
    }

    let temp_dir = tempfile::tempdir().unwrap();
    let root = TestRoot::new(temp_dir.path()).unwrap();

    // Create the target file first
    root.main().write("test content").unwrap();

    // Create the structure (which should create the symlink)
    root.sync().unwrap();

    // Verify main file exists
    let main_path = root.main();
    assert!(main_path.exists(), "Main file should exist");

    // Verify backup is a symlink
    let backup_path = root.backup();
    assert!(backup_path.exists(), "Backup symlink should exist");

    // Verify it's actually a symlink
    let metadata = fs::symlink_metadata(backup_path.as_path()).unwrap();
    assert!(metadata.is_symlink(), "Backup should be a symlink");

    // Verify symlink points to main
    let link_target = fs::read_link(backup_path.as_path()).unwrap();
    assert_eq!(link_target.file_name().unwrap(), "main.txt");
}

#[test]
#[cfg(unix)]
fn test_nested_symlink() {
    tree_type! {
        TestRoot {
            config/ {
                #[default("primary config")]
                primary("primary.toml"),
                #[symlink(primary)]
                secondary("secondary.toml")
            }
        }
    }

    let temp_dir = tempfile::tempdir().unwrap();
    let root = TestRoot::new(temp_dir.path()).unwrap();

    // Create the target file first
    root.config().primary().write("test config").unwrap();

    // Create the structure (which should create the symlink)
    root.sync().unwrap();

    // Verify symlink was created
    let secondary = root.config().secondary();
    assert!(secondary.exists(), "Secondary symlink should exist");

    let metadata = fs::symlink_metadata(secondary.as_path()).unwrap();
    assert!(metadata.is_symlink(), "Secondary should be a symlink");
}