Skip to content

Commit e2d3314

Browse files
committed
test: Adding test cases
1 parent 6112510 commit e2d3314

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/repositories/monitor.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,4 +590,34 @@ mod tests {
590590
let err = result.unwrap_err();
591591
assert!(err.to_string().contains("references non-existent trigger"));
592592
}
593+
594+
#[test]
595+
fn test_load_from_path_error_handling() {
596+
// Create a temporary directory for testing
597+
let temp_dir = TempDir::new().unwrap();
598+
let invalid_path = temp_dir.path().join("non_existent_monitor.json");
599+
600+
// Create a repository instance
601+
let repository =
602+
MonitorRepository::<NetworkRepository, TriggerRepository>::new_with_monitors(
603+
HashMap::new(),
604+
);
605+
606+
// Attempt to load from non-existent path
607+
let result = repository.load_from_path(Some(&invalid_path), None, None);
608+
609+
// Verify error handling
610+
assert!(result.is_err());
611+
let err = result.unwrap_err();
612+
match err {
613+
RepositoryError::LoadError(message) => {
614+
assert!(message.to_string().contains("Failed to load monitors"));
615+
// Verify the error contains the path in its metadata
616+
assert!(message
617+
.to_string()
618+
.contains(&invalid_path.display().to_string()));
619+
}
620+
_ => panic!("Expected RepositoryError::LoadError"),
621+
}
622+
}
593623
}

0 commit comments

Comments
 (0)