use super::*;
#[test]
fn an_empty_dir_has_no_daemon_marker() {
let dir = tempfile::tempdir().unwrap();
assert_eq!(daemon_marker(dir.path()).unwrap(), None);
}
#[test]
fn the_client_store_is_not_a_daemon_marker() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join(CLIENT_BUYER_DB_FILE), b"x").unwrap();
assert_eq!(daemon_marker(dir.path()).unwrap(), None);
}
#[test]
fn a_data_dir_missing_only_the_buyer_store_is_still_a_node_s() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join(NODE_LANES_DB_FILE), b"x").unwrap();
std::fs::write(dir.path().join(NODE_SETTLE_DB_FILE), b"x").unwrap();
assert_eq!(daemon_marker(dir.path()).unwrap(), Some(NODE_LANES_DB_FILE));
}
#[test]
fn every_daemon_store_file_marks_the_dir() {
for name in DAEMON_STORE_FILES {
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join(name), b"x").unwrap();
assert_eq!(daemon_marker(dir.path()).unwrap(), Some(*name), "{name}");
}
}
#[test]
fn a_stat_error_is_not_read_as_no_marker() {
let dir = tempfile::tempdir().unwrap();
let not_a_dir = dir.path().join("data");
std::fs::write(¬_a_dir, b"x").unwrap();
let err = daemon_marker(¬_a_dir).unwrap_err();
assert_ne!(err.kind(), io::ErrorKind::NotFound);
assert!(err.to_string().contains("failed to stat"), "{err}");
}