use std::path::PathBuf;
use std::process;
pub fn socket_addr(app_name: &str, include_pid: bool) -> PathBuf {
let mut addr = crate::dirs::temp().join("thcon").join(app_name);
if include_pid {
addr.push(process::id().to_string() + ".sock");
} else {
addr.set_extension("sock");
}
addr
}
#[cfg(not(windows))]
#[test]
fn app_without_pid() {
assert_eq!(
PathBuf::from("/tmp/thcon/some_app.sock"),
socket_addr("some_app", false),
)
}
#[cfg(not(windows))]
#[test]
fn app_with_pid() {
let pid = process::id().to_string();
assert_eq!(
PathBuf::from(format!("/tmp/thcon/some_app/{}.sock", pid)),
socket_addr("some_app", true),
)
}