From f460f5b94474b0c983b47f9c82162bcbb2de660c Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 16 Apr 2024 21:54:56 -0400 Subject: [PATCH] Add invalid data test for Index/Index2 --- src/index.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/index.rs b/src/index.rs index c8067e8..13933db 100755 --- a/src/index.rs +++ b/src/index.rs @@ -160,4 +160,31 @@ impl Index2File { let hash = Index2File::calculate_hash(path); self.entries.iter().find(|s| s.hash == hash) } -} \ No newline at end of file +} + +#[cfg(test)] +mod tests { + use std::path::PathBuf; + + use super::*; + + #[test] + fn test_index_invalid() { + let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + d.push("resources/tests"); + d.push("random"); + + // Feeding it invalid data should not panic + IndexFile::from_existing(d.to_str().unwrap()); + } + + #[test] + fn test_index2_invalid() { + let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + d.push("resources/tests"); + d.push("random"); + + // Feeding it invalid data should not panic + Index2File::from_existing(d.to_str().unwrap()); + } +}