T-47: tests
This commit is contained in:
parent
37b5c6d7d1
commit
199f7beecd
2 changed files with 467 additions and 0 deletions
88
tools/curate-etl/tests/cli.rs
Normal file
88
tools/curate-etl/tests/cli.rs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
//! QA end-to-end tests for the `curate-etl` binary (T-47 / M1.2a CLI contract).
|
||||
|
||||
use std::process::{Command, Output};
|
||||
|
||||
fn run(args: &[&str]) -> Output {
|
||||
Command::new(env!("CARGO_BIN_EXE_curate-etl"))
|
||||
.args(args)
|
||||
.output()
|
||||
.expect("spawn curate-etl binary")
|
||||
}
|
||||
|
||||
fn stdout(o: &Output) -> String {
|
||||
String::from_utf8_lossy(&o.stdout).into_owned()
|
||||
}
|
||||
|
||||
fn stderr(o: &Output) -> String {
|
||||
String::from_utf8_lossy(&o.stderr).into_owned()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_args_and_help_print_usage_and_succeed() {
|
||||
for args in [&[][..], &["--help"][..], &["-h"][..]] {
|
||||
let out = run(args);
|
||||
assert!(out.status.success(), "{args:?}: {}", stderr(&out));
|
||||
let text = stdout(&out);
|
||||
assert!(text.contains("Usage:"), "{args:?}: {text}");
|
||||
assert!(text.contains("bench-split"), "{args:?}: {text}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_prints_package_name_and_version() {
|
||||
for flag in ["--version", "-V"] {
|
||||
let out = run(&[flag]);
|
||||
assert!(out.status.success());
|
||||
assert_eq!(
|
||||
stdout(&out).trim(),
|
||||
format!("curate-etl {}", env!("CARGO_PKG_VERSION"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_invocations_exit_nonzero_with_usage_on_stderr() {
|
||||
for args in [
|
||||
&["--version", "--offine"][..],
|
||||
&["--help", "--bad"][..],
|
||||
&["bench-split", "abc"][..],
|
||||
&["bench-split", "0"][..],
|
||||
&["bench-split", "-5"][..],
|
||||
&["bench-split", "10", "20"][..],
|
||||
&["--unknown"][..],
|
||||
&["export"][..],
|
||||
] {
|
||||
let out = run(args);
|
||||
assert!(!out.status.success(), "{args:?} should fail");
|
||||
assert_eq!(out.status.code(), Some(1), "{args:?}");
|
||||
let err = stderr(&out);
|
||||
assert!(err.contains("error:"), "{args:?}: {err}");
|
||||
assert!(err.contains("Usage:"), "{args:?}: {err}");
|
||||
assert!(stdout(&out).is_empty(), "{args:?} wrote to stdout");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bench_split_small_run_is_headless_deterministic_and_reports_rates() {
|
||||
let a = run(&["bench-split", "1000"]);
|
||||
let b = run(&["bench-split", "1000"]);
|
||||
assert!(a.status.success(), "{}", stderr(&a));
|
||||
assert!(b.status.success(), "{}", stderr(&b));
|
||||
|
||||
let text = stdout(&a);
|
||||
assert!(
|
||||
text.contains("keys=20000 keys_with_splits=12153 events=18999"),
|
||||
"{text}"
|
||||
);
|
||||
assert!(text.contains("rows=1000 "), "{text}");
|
||||
assert!(text.contains("rows/s"), "{text}");
|
||||
assert!(text.contains("ns/row"), "{text}");
|
||||
assert!(text.contains("checksum=20285840610.475"), "{text}");
|
||||
|
||||
let checksum = |s: &str| {
|
||||
s.split_whitespace()
|
||||
.find(|t| t.starts_with("checksum="))
|
||||
.map(str::to_owned)
|
||||
};
|
||||
assert_eq!(checksum(&text), checksum(&stdout(&b)));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue