use d_engine_server::EmbeddedEngine;
use std::io::Write;
use std::time::Duration;
#[tokio::test]
async fn test_start_with_no_config_path_env() {
unsafe {
std::env::remove_var("CONFIG_PATH");
}
let temp_dir = tempfile::tempdir().unwrap();
let config_path = temp_dir.path().join("engine.toml");
let db_path = temp_dir.path().join("db");
let mut file = std::fs::File::create(&config_path).unwrap();
write!(
file,
r#"
[cluster]
node_id = 1
db_root_dir = "{}"
[[cluster.initial_cluster]]
id = 1
address = "127.0.0.1:0"
role = 3
status = 3
"#,
db_path.display()
)
.unwrap();
drop(file);
let engine = EmbeddedEngine::start_with(config_path.to_str().unwrap())
.await
.expect("Should start without CONFIG_PATH env");
let leader = engine.wait_ready(Duration::from_secs(5)).await.expect("Should elect leader");
assert_eq!(leader.leader_id, 1);
engine.stop().await.expect("Should stop cleanly");
}