T-202: tests
This commit is contained in:
parent
8f3126cf30
commit
8b93a58ec7
1 changed files with 182 additions and 0 deletions
|
|
@ -241,3 +241,185 @@ fn cli_missing_te_data_exits_nonzero_with_single_line_escaped_error_and_no_parqu
|
|||
);
|
||||
assert!(!cli_out.exists(), "out dir must not be created on failure");
|
||||
}
|
||||
|
||||
// ---- QA edge cases (T-202) ----
|
||||
|
||||
fn run_cli_paths(te_data: &Path, series_map: &Path, out: &Path) -> std::process::Output {
|
||||
cli()
|
||||
.arg("--te-data")
|
||||
.arg(te_data)
|
||||
.arg("--series-map")
|
||||
.arg(series_map)
|
||||
.arg("--out")
|
||||
.arg(out)
|
||||
.output()
|
||||
.expect("run curate-macro")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_help_lists_curate_macro_and_parse_errors_print_usage_without_writing() {
|
||||
let help = Command::new(env!("CARGO_BIN_EXE_curate-etl"))
|
||||
.arg("--help")
|
||||
.output()
|
||||
.expect("run --help");
|
||||
assert!(help.status.success(), "{help:?}");
|
||||
let help_text = String::from_utf8(help.stdout).expect("utf-8 help");
|
||||
assert!(
|
||||
help_text.contains("curate-macro --te-data <path> --series-map <path> --out <dir>"),
|
||||
"{help_text}"
|
||||
);
|
||||
|
||||
let dir = TempDir::new("parse-error");
|
||||
let (te_data_path, series_map_path) = write_policy_rate_fixture(&dir.0);
|
||||
let cli_out = dir.0.join("cli_out");
|
||||
|
||||
// `--mongo-uri` is not a file-mode flag; it must be rejected before any run.
|
||||
let result = cli()
|
||||
.arg("--te-data")
|
||||
.arg(&te_data_path)
|
||||
.arg("--series-map")
|
||||
.arg(&series_map_path)
|
||||
.arg("--out")
|
||||
.arg(&cli_out)
|
||||
.args(["--mongo-uri", "mongodb://user:secret@host:27017/stock"])
|
||||
.output()
|
||||
.expect("run curate-macro");
|
||||
|
||||
assert_eq!(result.status.code(), Some(1), "{result:?}");
|
||||
assert!(result.stdout.is_empty(), "{result:?}");
|
||||
let stderr = String::from_utf8(result.stderr).expect("utf-8 stderr");
|
||||
assert!(
|
||||
stderr.starts_with("error: unknown flag '--mongo-uri' for curate-macro\n"),
|
||||
"{stderr:?}"
|
||||
);
|
||||
assert!(stderr.contains("Usage:"), "{stderr:?}");
|
||||
assert!(
|
||||
!stderr.contains("secret"),
|
||||
"rejected flag value must not be echoed: {stderr:?}"
|
||||
);
|
||||
assert!(
|
||||
!cli_out.exists(),
|
||||
"out dir must not be created on parse error"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_runtime_failures_keep_existing_parquet_byte_identical() {
|
||||
let dir = TempDir::new("preserve");
|
||||
let (te_data_path, series_map_path) = write_policy_rate_fixture(&dir.0);
|
||||
let out = dir.0.join("out");
|
||||
|
||||
let first = run_cli_paths(&te_data_path, &series_map_path, &out);
|
||||
assert!(first.status.success(), "{first:?}");
|
||||
let parquet = out.join("macro/part.parquet");
|
||||
let original = fs::read(&parquet).expect("read published parquet");
|
||||
|
||||
let bad_header = dir.0.join("bad_header.tsv");
|
||||
fs::write(&bad_header, "not\ta\theader\n").expect("write bad tsv");
|
||||
let corrupt_bson = dir.0.join("corrupt.bson");
|
||||
// Declares a 64-byte document but provides only 8 bytes.
|
||||
fs::write(&corrupt_bson, [64u8, 0, 0, 0, 1, 2, 3, 4]).expect("write corrupt bson");
|
||||
let missing_map = dir.0.join("missing_map.tsv");
|
||||
|
||||
for (label, te, map, role) in [
|
||||
("bad series-map header", &te_data_path, &bad_header, None),
|
||||
(
|
||||
"truncated teData",
|
||||
&corrupt_bson,
|
||||
&series_map_path,
|
||||
Some("te-data"),
|
||||
),
|
||||
(
|
||||
"missing series-map",
|
||||
&te_data_path,
|
||||
&missing_map,
|
||||
Some("series-map"),
|
||||
),
|
||||
] {
|
||||
let result = run_cli_paths(te, map, &out);
|
||||
assert_eq!(result.status.code(), Some(1), "{label}: {result:?}");
|
||||
assert!(result.stdout.is_empty(), "{label}: {result:?}");
|
||||
let stderr = String::from_utf8(result.stderr).expect("utf-8 stderr");
|
||||
assert_eq!(stderr.lines().count(), 1, "{label}: {stderr:?}");
|
||||
assert!(stderr.starts_with("error: "), "{label}: {stderr:?}");
|
||||
assert!(!stderr.contains("Usage:"), "{label}: {stderr:?}");
|
||||
if let Some(role) = role {
|
||||
assert!(stderr.contains(role), "{label}: {stderr:?}");
|
||||
}
|
||||
assert_eq!(
|
||||
fs::read(&parquet).expect("re-read parquet"),
|
||||
original,
|
||||
"{label}: failed run must not touch the published parquet"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_rerun_on_same_inputs_is_byte_deterministic() {
|
||||
let dir = TempDir::new("rerun");
|
||||
let (te_data_path, series_map_path) = write_policy_rate_fixture(&dir.0);
|
||||
let out_a = dir.0.join("out_a");
|
||||
let out_b = dir.0.join("out_b");
|
||||
|
||||
let a = run_cli_paths(&te_data_path, &series_map_path, &out_a);
|
||||
let b = run_cli_paths(&te_data_path, &series_map_path, &out_b);
|
||||
assert!(a.status.success() && b.status.success(), "{a:?} {b:?}");
|
||||
assert_eq!(a.stdout, b.stdout);
|
||||
assert_eq!(
|
||||
fs::read(out_a.join("macro/part.parquet")).expect("read a"),
|
||||
fs::read(out_b.join("macro/part.parquet")).expect("read b")
|
||||
);
|
||||
|
||||
// Republishing into the same directory replaces the file with identical bytes.
|
||||
let again = run_cli_paths(&te_data_path, &series_map_path, &out_a);
|
||||
assert!(again.status.success(), "{again:?}");
|
||||
assert_eq!(
|
||||
fs::read(out_a.join("macro/part.parquet")).expect("read a again"),
|
||||
fs::read(out_b.join("macro/part.parquet")).expect("read b")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_unmapped_only_input_succeeds_and_matches_runner_report() {
|
||||
let dir = TempDir::new("unmapped");
|
||||
let te_data_path = dir.0.join("teData.bson");
|
||||
let series_map_path = dir.0.join("macro_series_map.tsv");
|
||||
let doc = make_te_data_doc(
|
||||
"UNMAPPED",
|
||||
"Atlantis",
|
||||
"Interest Rate",
|
||||
&[("2024-03-20", 1.25)],
|
||||
&[],
|
||||
);
|
||||
fs::write(&te_data_path, doc.as_bytes()).expect("write teData");
|
||||
fs::write(
|
||||
&series_map_path,
|
||||
format!(
|
||||
"{MACRO_SERIES_MAP_HEADER}\nFDTR\tUnited States\tInterest Rate\tUS\tfed_funds_rate\tpolicy_rate\n"
|
||||
),
|
||||
)
|
||||
.expect("write tsv");
|
||||
|
||||
let baseline_out = dir.0.join("baseline_out");
|
||||
let baseline = run_curate_macro(&CurateMacroArgs {
|
||||
te_data: te_data_path.clone(),
|
||||
series_map: series_map_path.clone(),
|
||||
out_dir: baseline_out.clone(),
|
||||
})
|
||||
.expect("library run");
|
||||
assert_eq!(baseline.curate_stats.rows_out, 0);
|
||||
|
||||
let cli_out = dir.0.join("cli_out");
|
||||
let result = run_cli_paths(&te_data_path, &series_map_path, &cli_out);
|
||||
assert!(result.status.success(), "{result:?}");
|
||||
assert!(result.stderr.is_empty(), "{result:?}");
|
||||
assert_eq!(
|
||||
String::from_utf8(result.stdout).expect("utf-8 stdout"),
|
||||
format!("{}\n", format_curate_macro_report(&baseline))
|
||||
);
|
||||
assert_eq!(
|
||||
cli_out.join("macro/part.parquet").exists(),
|
||||
baseline_out.join("macro/part.parquet").exists(),
|
||||
"CLI and runner must agree on zero-row publication"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue