Add test for creating symlink nodes and fix code to pass test

This commit is contained in:
Nathan Fisher 2023-12-11 19:29:29 -05:00
parent 49f1954a57
commit ff1afa6453

View File

@ -132,7 +132,7 @@ impl Node {
) -> Result<Self, Error> {
let name = String::from(path);
let fd = fs::File::open(path)?;
let meta = fd.metadata()?;
let meta = fs::symlink_metadata(path)?;
let mode = meta.mode();
let uid = meta.uid();
let gid = meta.gid();
@ -310,12 +310,12 @@ impl Node {
#[cfg(test)]
mod tests {
use super::*;
use std::fmt::Write;
use std::{fmt::Write, fs::remove_file};
static LI: &[u8] = include_bytes!("../test/li.txt");
#[test]
fn from_path() {
fn from_file_path() {
let links = Mutex::new(HashMap::new());
let node = Node::from_path("test/li.txt", Algorithm::Sha256, &links).unwrap();
let FileType::Normal(f) = node.filetype else {
@ -336,7 +336,20 @@ mod tests {
}
#[test]
fn load_store() {
fn from_symlink_path() {
let _res = remove_file("test/lilnk.txt");
symlink("li.txt", "test/lilnk.txt").unwrap();
let links = Mutex::new(HashMap::new());
let node = Node::from_path("test/lilnk.txt", Algorithm::Skip, &links).unwrap();
let FileType::SoftLink(tgt) = node.filetype else {
eprintln!("Incorrect filetype: {:?}", node.filetype);
panic!();
};
assert_eq!(tgt, "li.txt");
}
#[test]
fn load_store_file() {
{
let fd = std::fs::File::create("test/li.node").unwrap();
let mut writer = std::io::BufWriter::new(fd);