pub fn daemon_running_status_token() -> &'static str {
"running"
}
pub fn daemon_not_running_status_token() -> &'static str {
"not_running"
}
pub fn daemon_stopped_status_token() -> &'static str {
"stopped"
}
pub fn daemon_status_running_line(
ok: bool,
version: u32,
uptime_s: u64,
mount_count: usize,
materialized_count: usize,
) -> String {
format!(
"daemon: ok={ok} version={version} uptime_s={uptime_s} mount_count={mount_count} materialized_count={materialized_count}"
)
}
pub fn daemon_status_not_running_line(endpoint_path: &str, materialized_count: usize) -> String {
format!(
"daemon: not running (no live endpoint at {endpoint_path}) materialized_count={materialized_count}"
)
}
pub fn daemon_stop_not_running_line() -> &'static str {
"daemon: not running"
}
pub fn daemon_stop_stopped_line() -> &'static str {
"daemon: stopped"
}
pub fn daemon_materialized_threads_header() -> &'static str {
"materialized threads:"
}
pub fn daemon_materialized_thread_line(
thread: &str,
state: &str,
files: usize,
tree_short: &str,
) -> String {
format!(" {thread} (state={state}, files={files}, tree={tree_short})")
}
pub fn daemon_short_tree(tree: &str) -> &str {
&tree[..tree.len().min(12)]
}
pub fn daemon_health_failed_kind() -> &'static str {
"daemon_health_failed"
}
pub fn daemon_unexpected_response_kind() -> &'static str {
"daemon_unexpected_response"
}
pub fn daemon_shutdown_refused_kind() -> &'static str {
"daemon_shutdown_refused"
}
pub fn daemon_stop_status_token(was_running: bool) -> &'static str {
if was_running {
daemon_stopped_status_token()
} else {
daemon_not_running_status_token()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn status_tokens_and_lines() {
assert_eq!(daemon_running_status_token(), "running");
assert_eq!(daemon_not_running_status_token(), "not_running");
assert_eq!(daemon_stopped_status_token(), "stopped");
assert_eq!(daemon_stop_status_token(true), "stopped");
assert_eq!(daemon_stop_status_token(false), "not_running");
let running = daemon_status_running_line(true, 1, 42, 2, 3);
assert!(running.contains("ok=true"));
assert!(running.contains("uptime_s=42"));
assert!(running.contains("materialized_count=3"));
let idle = daemon_status_not_running_line("/tmp/ep.json", 1);
assert!(idle.contains("not running"));
assert!(idle.contains("/tmp/ep.json"));
assert_eq!(daemon_stop_not_running_line(), "daemon: not running");
assert_eq!(daemon_stop_stopped_line(), "daemon: stopped");
}
#[test]
fn materialized_line_and_kinds() {
assert_eq!(
daemon_materialized_thread_line("feat", "abc", 10, "deadbeefcafe"),
" feat (state=abc, files=10, tree=deadbeefcafe)"
);
assert_eq!(daemon_short_tree("0123456789abcdef"), "0123456789ab");
assert_eq!(daemon_health_failed_kind(), "daemon_health_failed");
assert_eq!(
daemon_unexpected_response_kind(),
"daemon_unexpected_response"
);
assert_eq!(daemon_shutdown_refused_kind(), "daemon_shutdown_refused");
assert_eq!(
daemon_materialized_threads_header(),
"materialized threads:"
);
}
}