Ajout de tests unitaires et mise à jour du rapport de couverture
Ajout de tests unitaires pour les fonctions de gestion des processus et des protocoles de transport. Mise à jour de la configuration de couverture pour générer un rapport JSON au lieu de HTML. Les tests couvrent les formats de chaînes OS, les propriétés des structures ProcessPortInfo et TransportProtocol, ainsi que les comportements de base de la fonction find_process_using_port.
This commit is contained in:
4
Makefile
4
Makefile
@@ -141,8 +141,8 @@ bench:
|
|||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
@echo "$(YELLOW)→ Génération du rapport de couverture...$(NC)"
|
@echo "$(YELLOW)→ Génération du rapport de couverture...$(NC)"
|
||||||
$(CARGO) tarpaulin --out Html --output-dir target/coverage
|
$(CARGO) tarpaulin --out json --output-dir target/coverage
|
||||||
@echo "$(GREEN)✓ Rapport disponible dans target/coverage/index.html$(NC)"
|
@echo "$(GREEN)✓ Rapport disponible dans target/coverage/tarpaulin-report.json$(NC)"
|
||||||
|
|
||||||
jjnew:
|
jjnew:
|
||||||
@echo "$(YELLOW)→ Création d'un nouveau commit...$(NC)"
|
@echo "$(YELLOW)→ Création d'un nouveau commit...$(NC)"
|
||||||
|
|||||||
27
src/lib.rs
27
src/lib.rs
@@ -18,6 +18,33 @@
|
|||||||
pub mod ip_utils;
|
pub mod ip_utils;
|
||||||
|
|
||||||
pub use ip_utils::guess_local_ip;
|
pub use ip_utils::guess_local_ip;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_os_string_format() {
|
||||||
|
let os = get_os_string();
|
||||||
|
assert!(!os.is_empty());
|
||||||
|
assert!(os.contains("/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_os_string_contains_os_type() {
|
||||||
|
let os = get_os_string();
|
||||||
|
// Les types d'OS retournés par os_info peuvent varier, on vérifie juste le format
|
||||||
|
let parts: Vec<&str> = os.split('/').collect();
|
||||||
|
assert_eq!(
|
||||||
|
parts.len(),
|
||||||
|
2,
|
||||||
|
"OS string should have format 'Type/Version'"
|
||||||
|
);
|
||||||
|
assert!(!parts[0].is_empty(), "OS type should not be empty");
|
||||||
|
assert!(!parts[1].is_empty(), "OS version should not be empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod process;
|
pub mod process;
|
||||||
pub use process::{find_process_using_port, ProcessPortInfo, TransportProtocol};
|
pub use process::{find_process_using_port, ProcessPortInfo, TransportProtocol};
|
||||||
/// Retourne une chaîne décrivant le système d'exploitation et sa version.
|
/// Retourne une chaîne décrivant le système d'exploitation et sa version.
|
||||||
|
|||||||
@@ -86,3 +86,77 @@ fn build_process_info(
|
|||||||
port,
|
port,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_transport_protocol_tcp() {
|
||||||
|
let protocol = TransportProtocol::Tcp;
|
||||||
|
assert!(matches!(protocol, TransportProtocol::Tcp));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_transport_protocol_udp() {
|
||||||
|
let protocol = TransportProtocol::Udp;
|
||||||
|
assert!(matches!(protocol, TransportProtocol::Udp));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_process_port_info_debug() {
|
||||||
|
let info = ProcessPortInfo {
|
||||||
|
pid: 1234,
|
||||||
|
process_name: "test".to_string(),
|
||||||
|
owner: "user".to_string(),
|
||||||
|
port: 8080,
|
||||||
|
};
|
||||||
|
let debug_str = format!("{:?}", info);
|
||||||
|
assert!(debug_str.contains("1234"));
|
||||||
|
assert!(debug_str.contains("test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_process_port_info_clone() {
|
||||||
|
let info = ProcessPortInfo {
|
||||||
|
pid: 5678,
|
||||||
|
process_name: "test_proc".to_string(),
|
||||||
|
owner: "test_user".to_string(),
|
||||||
|
port: 9000,
|
||||||
|
};
|
||||||
|
let cloned = info.clone();
|
||||||
|
assert_eq!(info.pid, cloned.pid);
|
||||||
|
assert_eq!(info.process_name, cloned.process_name);
|
||||||
|
assert_eq!(info.owner, cloned.owner);
|
||||||
|
assert_eq!(info.port, cloned.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_process_using_port_invalid() {
|
||||||
|
let result = find_process_using_port(65535, TransportProtocol::Tcp);
|
||||||
|
assert!(result.is_none() || result.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_transport_protocol_copy() {
|
||||||
|
let protocol = TransportProtocol::Tcp;
|
||||||
|
let copied = protocol;
|
||||||
|
assert!(matches!(copied, TransportProtocol::Tcp));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_transport_protocol_traits() {
|
||||||
|
let tcp = TransportProtocol::Tcp;
|
||||||
|
let udp = TransportProtocol::Udp;
|
||||||
|
|
||||||
|
assert_eq!(format!("{:?}", tcp), "Tcp");
|
||||||
|
assert_eq!(format!("{:?}", udp), "Udp");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_build_process_info_none() {
|
||||||
|
let mut system = System::new();
|
||||||
|
let result = build_process_info(&mut system, 8080, None);
|
||||||
|
assert!(result.is_none());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user