From b534cf6d49b6ae07cf493b957e3f933d7ee30b2e Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Sat, 16 Dec 2023 00:40:19 -0500 Subject: [PATCH] Create test for load/store fifo node --- src/node.rs | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/node.rs b/src/node.rs index f992755..cda14b3 100644 --- a/src/node.rs +++ b/src/node.rs @@ -407,8 +407,8 @@ mod tests { #[test] fn load_store_file() { { - let fd = std::fs::File::create("test/li.node").unwrap(); - let mut writer = std::io::BufWriter::new(fd); + let fd = fs::File::create("test/li.node").unwrap(); + let mut writer = BufWriter::new(fd); let links = Mutex::new(HashMap::new()); let node = Node::from_path("test/li.txt", Algorithm::Sha1, &links).unwrap(); let FileType::Normal(_) = node.filetype else { @@ -418,7 +418,7 @@ mod tests { node.write(&mut writer).unwrap(); } let meta = fs::metadata("test/li.txt").unwrap(); - let fd = std::fs::File::open("test/li.node").unwrap(); + let fd = fs::File::open("test/li.node").unwrap(); let mut reader = BufReader::new(fd); let node = Node::read(&mut reader).unwrap(); assert_eq!(meta.mode() & 0o777, node.mode as u32); @@ -446,8 +446,8 @@ mod tests { let _res = remove_file("test/lilnk.txt"); symlink("li.txt", "test/lilnk.txt").unwrap(); let _res = remove_file("test/lilnk.node"); - let fd = std::fs::File::create("test/lilnk.node").unwrap(); - let mut writer = std::io::BufWriter::new(fd); + let fd = fs::File::create("test/lilnk.node").unwrap(); + let mut writer = BufWriter::new(fd); let links = Mutex::new(HashMap::new()); let node = Node::from_path("test/lilnk.txt", Algorithm::Sha1, &links).unwrap(); let FileType::SoftLink(ref tgt) = node.filetype else { @@ -473,8 +473,8 @@ mod tests { let _res = remove_file("test/lihlnk.txt"); fs::hard_link("test/li.txt", "test/lihlnk.txt").unwrap(); let _res = remove_file("test/lihlnk.node"); - let fd = std::fs::File::create("test/lihlnk.node").unwrap(); - let mut writer = std::io::BufWriter::new(fd); + let fd = fs::File::create("test/lihlnk.node").unwrap(); + let mut writer = BufWriter::new(fd); let links = Mutex::new(HashMap::new()); let _node = Node::from_path("test/li.txt", Algorithm::Sha1, &links).unwrap(); let node = Node::from_path("test/lihlnk.txt", Algorithm::Sha1, &links).unwrap(); @@ -495,6 +495,31 @@ mod tests { assert_eq!(tgt, "test/li.txt"); } + #[test] + fn load_store_fifo() { + { + let _res = remove_file("test/fifo"); + nix::mkfifo("test/fifo", 0o644).unwrap(); + let links = Mutex::new(HashMap::new()); + let node = Node::from_path("test/fifo", Algorithm::Skip, &links).unwrap(); + let FileType::Fifo = node.filetype else { + eprintln!("Incorrect filetype: {:?}", node.filetype); + panic!(); + }; + let _res = remove_file("test/fifo.node"); + let fd = fs::File::create("test/fifo.node").unwrap(); + let mut writer = BufWriter::new(fd); + node.write(&mut writer).unwrap(); + } + let fd = fs::File::open("test/fifo.node").unwrap(); + let mut reader = BufReader::new(fd); + let node = Node::read(&mut reader).unwrap(); + let FileType::Fifo = node.filetype else { + eprintln!("Read incorrect filetype: {:?}", node.filetype); + panic!(); + }; + } + #[test] fn extract_file() { let links = Mutex::new(HashMap::new());