Some checks failed
rust-ci / checks (push) Has been cancelled
- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI) - Sim: fix false Delivered after a route cut, derive traffic class from payload size, per-link airtime slots (link capacity, queueing) - Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers, drop unimplemented seed claims, uncheck store-and-forward - License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
156 lines
4 KiB
Rust
156 lines
4 KiB
Rust
//! End-to-end route/send/sim/wire tests against the real `icenetd` binary.
|
|
mod common;
|
|
|
|
use common::{run, stderr, stdout, temp};
|
|
|
|
#[test]
|
|
fn help_lists_all_commands() {
|
|
let output = run(&["help"]);
|
|
assert!(output.status.success());
|
|
let text = stdout(&output);
|
|
for command in [
|
|
"route",
|
|
"send",
|
|
"sim",
|
|
"policy",
|
|
"wire-encode",
|
|
"wire-decode",
|
|
] {
|
|
assert!(text.contains(command), "missing {command} in help");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn bulk_route_avoids_slow_radio() {
|
|
let output = run(&[
|
|
"route", "--from", "1", "--to", "3", "--class", "bulk", "--size", "5000000",
|
|
]);
|
|
assert!(output.status.success(), "stderr: {}", stderr(&output));
|
|
assert!(stdout(&output).contains("1-4-5-3"));
|
|
}
|
|
|
|
#[test]
|
|
fn bulk_route_reports_no_route_without_fast_links() {
|
|
let output = run(&[
|
|
"route",
|
|
"--from",
|
|
"1",
|
|
"--to",
|
|
"3",
|
|
"--class",
|
|
"bulk",
|
|
"--size",
|
|
"5000000",
|
|
"--disable",
|
|
"2,3,4",
|
|
]);
|
|
assert!(output.status.success());
|
|
assert!(stdout(&output).contains("NO_ROUTE"));
|
|
}
|
|
|
|
#[test]
|
|
fn text_route_may_use_slow_radio() {
|
|
let output = run(&[
|
|
"route",
|
|
"--from",
|
|
"1",
|
|
"--to",
|
|
"3",
|
|
"--class",
|
|
"text",
|
|
"--size",
|
|
"128",
|
|
"--disable",
|
|
"2,3,4",
|
|
]);
|
|
assert!(output.status.success());
|
|
assert!(stdout(&output).contains("1-2-3"));
|
|
}
|
|
|
|
#[test]
|
|
fn send_reports_delivered_message() {
|
|
let output = run(&[
|
|
"send", "--from", "1", "--to", "3", "--class", "text", "--size", "128", "--ticks", "1000",
|
|
]);
|
|
assert!(output.status.success());
|
|
assert!(stdout(&output).contains("status=Delivered"));
|
|
}
|
|
|
|
#[test]
|
|
fn send_reports_expired_message() {
|
|
let output = run(&[
|
|
"send",
|
|
"--from",
|
|
"1",
|
|
"--to",
|
|
"3",
|
|
"--class",
|
|
"bulk",
|
|
"--size",
|
|
"5000000",
|
|
"--disable",
|
|
"2,3,4",
|
|
"--ttl",
|
|
"1000",
|
|
"--ticks",
|
|
"2000",
|
|
]);
|
|
assert!(output.status.success(), "stderr: {}", stderr(&output));
|
|
assert!(stdout(&output).contains("status=Expired"));
|
|
}
|
|
|
|
#[test]
|
|
fn sim_writes_csv_and_json_exports() {
|
|
let csv = temp("metrics.csv");
|
|
let json = temp("scenario.json");
|
|
let output = run(&[
|
|
"sim",
|
|
"--csv",
|
|
csv.to_str().expect("utf8 path"),
|
|
"--json",
|
|
json.to_str().expect("utf8 path"),
|
|
]);
|
|
assert!(output.status.success(), "stderr: {}", stderr(&output));
|
|
assert!(stdout(&output).contains("expired=1"));
|
|
let csv_body = std::fs::read_to_string(&csv).expect("csv export");
|
|
assert!(csv_body.starts_with("id,from,to,class,bytes,status,"));
|
|
let json_body = std::fs::read_to_string(&json).expect("json export");
|
|
assert!(json_body.contains("\"messages\""));
|
|
let _ = std::fs::remove_file(csv);
|
|
let _ = std::fs::remove_file(json);
|
|
}
|
|
|
|
#[test]
|
|
fn wire_encoder_and_decoder_round_trip() {
|
|
let encoded = run(&[
|
|
"wire-encode",
|
|
"--service",
|
|
"7",
|
|
"--class",
|
|
"text",
|
|
"--text",
|
|
"hello",
|
|
]);
|
|
assert!(encoded.status.success(), "stderr: {}", stderr(&encoded));
|
|
let text = stdout(&encoded);
|
|
let hex = text
|
|
.lines()
|
|
.find_map(|line| line.strip_prefix("frame: "))
|
|
.expect("frame hex line")
|
|
.to_owned();
|
|
let decoded = run(&["wire-decode", "--hex", &hex]);
|
|
assert!(decoded.status.success(), "stderr: {}", stderr(&decoded));
|
|
let text = stdout(&decoded);
|
|
assert!(text.contains("class: Text"));
|
|
assert!(text.contains("service: 7"));
|
|
assert!(text.contains("payload: hello"));
|
|
}
|
|
|
|
#[test]
|
|
fn wire_decode_escapes_control_bytes() {
|
|
let output = run(&["wire-decode", "--hex", "494e0101000000000000000700020102"]);
|
|
assert!(output.status.success(), "stderr: {}", stderr(&output));
|
|
let text = stdout(&output);
|
|
assert!(text.contains("payload_hex: 0102"));
|
|
assert!(!text.contains('\u{1}'));
|
|
}
|