62 lines
2.0 KiB
Rust
62 lines
2.0 KiB
Rust
|
|
//! Milestone 1: `varde-ctl status` round-trips against a real daemon.
|
||
|
|
|
||
|
|
use std::process::Command;
|
||
|
|
use std::time::Duration;
|
||
|
|
|
||
|
|
use varde_daemon::config::Config;
|
||
|
|
|
||
|
|
/// Start an in-process daemon on an ephemeral socket, then run the real
|
||
|
|
/// varde-ctl binary against it.
|
||
|
|
#[test]
|
||
|
|
fn ctl_status_round_trips() {
|
||
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
||
|
|
let socket_path = dir.path().join("varde.sock");
|
||
|
|
let config = Config {
|
||
|
|
store_dir: dir.path().join("store"),
|
||
|
|
socket_path: socket_path.clone(),
|
||
|
|
max_upload_bytes_per_sec: 0,
|
||
|
|
max_download_bytes_per_sec: 0,
|
||
|
|
discovery: false,
|
||
|
|
wan_upload: false,
|
||
|
|
};
|
||
|
|
|
||
|
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||
|
|
.worker_threads(2)
|
||
|
|
.enable_all()
|
||
|
|
.build()
|
||
|
|
.expect("tokio runtime");
|
||
|
|
let _daemon = rt.spawn(varde_daemon::run(config));
|
||
|
|
|
||
|
|
// run() binds the socket synchronously at first poll; give it a beat.
|
||
|
|
let deadline = std::time::Instant::now() + Duration::from_secs(10);
|
||
|
|
while !socket_path.exists() && std::time::Instant::now() < deadline {
|
||
|
|
std::thread::sleep(Duration::from_millis(20));
|
||
|
|
}
|
||
|
|
|
||
|
|
let output = Command::new(env!("CARGO_BIN_EXE_varde-ctl"))
|
||
|
|
.args(["--socket", socket_path.to_str().unwrap(), "status"])
|
||
|
|
.output()
|
||
|
|
.expect("running varde-ctl");
|
||
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||
|
|
assert!(output.status.success(), "varde-ctl failed: {stderr}");
|
||
|
|
assert!(
|
||
|
|
stdout.contains("varde-daemon"),
|
||
|
|
"unexpected output: {stdout}"
|
||
|
|
);
|
||
|
|
|
||
|
|
let output = Command::new(env!("CARGO_BIN_EXE_varde-ctl"))
|
||
|
|
.args([
|
||
|
|
"--socket",
|
||
|
|
socket_path.to_str().unwrap(),
|
||
|
|
"--json",
|
||
|
|
"status",
|
||
|
|
])
|
||
|
|
.output()
|
||
|
|
.expect("running varde-ctl --json");
|
||
|
|
assert!(output.status.success());
|
||
|
|
let json: serde_json::Value =
|
||
|
|
serde_json::from_slice(&output.stdout).expect("--json output is JSON");
|
||
|
|
assert_eq!(json["ok"], true);
|
||
|
|
}
|