124 lines
3.7 KiB
Rust
124 lines
3.7 KiB
Rust
#[cfg(feature = "client")]
|
|
#[path = "../../irtt-integration-tests/tests/support/in_tree_server.rs"]
|
|
mod in_tree_server;
|
|
|
|
#[cfg(feature = "client")]
|
|
use irtt_server::ServerConfig;
|
|
use std::process::Command;
|
|
|
|
// Dispatch/help/availability belong to the application and run in every build.
|
|
#[test]
|
|
fn dispatcher_reports_and_runs_the_enabled_applets() {
|
|
let dispatcher = env!("CARGO_BIN_EXE_irtt-rs");
|
|
let help = Command::new(dispatcher).arg("--help").output().unwrap();
|
|
assert!(help.status.success());
|
|
let help = String::from_utf8(help.stdout).unwrap();
|
|
for (applet, enabled) in [
|
|
("client", cfg!(feature = "client")),
|
|
("server", cfg!(feature = "server")),
|
|
("tui", cfg!(feature = "tui")),
|
|
] {
|
|
let row = help
|
|
.lines()
|
|
.find(|line| line.trim_start().starts_with(applet))
|
|
.unwrap();
|
|
assert_eq!(row.contains("not available"), !enabled);
|
|
let output = Command::new(dispatcher)
|
|
.args([applet, "--help"])
|
|
.output()
|
|
.unwrap();
|
|
assert_eq!(output.status.success(), enabled, "{applet}");
|
|
if !enabled {
|
|
assert!(String::from_utf8(output.stderr)
|
|
.unwrap()
|
|
.contains("not available"));
|
|
}
|
|
}
|
|
let binaries = [
|
|
dispatcher,
|
|
#[cfg(feature = "client")]
|
|
env!("CARGO_BIN_EXE_irtt-client"),
|
|
#[cfg(feature = "server")]
|
|
env!("CARGO_BIN_EXE_irtt-server"),
|
|
#[cfg(feature = "tui")]
|
|
env!("CARGO_BIN_EXE_irtt-tui"),
|
|
];
|
|
for binary in binaries {
|
|
assert!(Command::new(binary)
|
|
.arg("--help")
|
|
.output()
|
|
.unwrap()
|
|
.status
|
|
.success());
|
|
assert!(!Command::new(binary)
|
|
.arg("--invalid-option")
|
|
.output()
|
|
.unwrap()
|
|
.status
|
|
.success());
|
|
}
|
|
}
|
|
|
|
// A real authenticated server detects broken client argument-to-config mapping.
|
|
#[cfg(feature = "client")]
|
|
#[test]
|
|
fn client_arguments_export_a_real_client_run() {
|
|
let dispatcher = env!("CARGO_BIN_EXE_irtt-rs");
|
|
for option in ["--dscp", "--ttl"] {
|
|
assert!(!Command::new(dispatcher)
|
|
.args(["client", option, "256", "127.0.0.1:9"])
|
|
.output()
|
|
.unwrap()
|
|
.status
|
|
.success());
|
|
}
|
|
let server =
|
|
in_tree_server::InTreeServer::start(ServerConfig::default().with_hmac_key(b"cli-test"));
|
|
let output = Command::new(dispatcher)
|
|
.args([
|
|
"client",
|
|
"--duration",
|
|
"100ms",
|
|
"--interval",
|
|
"20ms",
|
|
"--hmac",
|
|
"cli-test",
|
|
"--length",
|
|
"128",
|
|
"--sfill",
|
|
"pattern:ab",
|
|
"--clock",
|
|
"wall",
|
|
"--tstamp",
|
|
"both",
|
|
"--stats",
|
|
"both",
|
|
"--ttl",
|
|
"64",
|
|
"--format",
|
|
"jsonl",
|
|
"--columns",
|
|
"target,event,bytes",
|
|
&format!("edge={}", server.addr),
|
|
])
|
|
.output()
|
|
.unwrap();
|
|
assert!(
|
|
output.status.success(),
|
|
"{}",
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
let rows: Vec<_> = stdout.lines().collect();
|
|
assert!(!rows.is_empty());
|
|
assert!(rows.iter().all(|row| row.starts_with('{')
|
|
&& row.ends_with('}')
|
|
&& row.contains("\"target\":\"edge\"")));
|
|
assert!(rows
|
|
.iter()
|
|
.any(|row| row.contains("\"event\":\"echo_reply\"") && row.contains("\"bytes\":128")));
|
|
assert!(rows
|
|
.iter()
|
|
.any(|row| row.contains("\"event\":\"session_closed\"")));
|
|
}
|