use sidekick::utils::{compute_socket_path_with_pid, find_matching_sockets};
#[test]
fn test_compute_socket_path_with_pid() {
let pid = 12345;
let socket_path = compute_socket_path_with_pid(pid).expect("Failed to compute socket path");
assert!(socket_path.starts_with("/tmp"));
let path_str = socket_path.to_string_lossy();
assert!(path_str.ends_with("-12345.sock"));
let filename = socket_path.file_name().unwrap().to_string_lossy();
assert!(filename.len() > 70); }
#[test]
fn test_compute_socket_path_deterministic() {
let pid = 99999;
let path1 = compute_socket_path_with_pid(pid).expect("Failed to compute socket path");
let path2 = compute_socket_path_with_pid(pid).expect("Failed to compute socket path");
assert_eq!(path1, path2);
}
#[test]
fn test_compute_socket_path_different_pids() {
let pid1 = 11111;
let pid2 = 22222;
let path1 = compute_socket_path_with_pid(pid1).expect("Failed to compute socket path");
let path2 = compute_socket_path_with_pid(pid2).expect("Failed to compute socket path");
assert_ne!(path1, path2);
let name1 = path1.file_name().unwrap().to_string_lossy();
let name2 = path2.file_name().unwrap().to_string_lossy();
let pid_str1 = name1
.strip_suffix(".sock")
.and_then(|s| s.split('-').next_back())
.unwrap();
let pid_str2 = name2
.strip_suffix(".sock")
.and_then(|s| s.split('-').next_back())
.unwrap();
assert_eq!(pid_str1, "11111");
assert_eq!(pid_str2, "22222");
}
#[test]
fn test_find_matching_sockets_empty() {
let sockets = find_matching_sockets().expect("Failed to find sockets");
assert!(sockets.is_empty() || !sockets.is_empty());
}
#[test]
fn test_find_matching_sockets_filters_nonexistent() {
let sockets = find_matching_sockets().expect("Failed to find sockets");
for socket in &sockets {
assert!(socket.exists(), "Socket path should exist: {:?}", socket);
}
}
#[test]
fn test_socket_path_pattern() {
let pid = 123;
let socket_path = compute_socket_path_with_pid(pid).expect("Failed to compute socket path");
let path_str = socket_path.to_string_lossy();
let parts: Vec<&str> = path_str.rsplitn(2, '/').collect();
assert_eq!(parts.len(), 2);
assert_eq!(parts[1], "/tmp");
let filename = parts[0];
let components: Vec<&str> = filename.split('-').collect();
assert_eq!(components.len(), 2);
assert!(components[0].len() == 64); assert!(components[1].ends_with(".sock"));
}