Refactor run CLI tests to use snapshots

This commit is contained in:
Bryan Helmkamp 2026-03-30 12:55:56 -04:00
parent d50b3187e5
commit 529899d71f
3 changed files with 626 additions and 420 deletions

View file

@ -93,7 +93,7 @@ chrono = { workspace = true }
[dev-dependencies]
assert_cmd = "2"
insta = { workspace = true }
insta = { workspace = true, features = ["filters"] }
paste = "1"
predicates = "3"
serde_json.workspace = true

File diff suppressed because it is too large Load diff

View file

@ -265,6 +265,45 @@ impl TestContext {
std::fs::write(&full, content).expect("failed to write file");
self
}
/// Find a run directory whose name ends with `run_id_suffix`.
pub fn find_run_dir(&self, run_id_suffix: &str) -> PathBuf {
let runs_dir = self.storage_dir.join("runs");
std::fs::read_dir(&runs_dir)
.expect("runs directory should exist")
.flatten()
.map(|entry| entry.path())
.find(|path| {
path.is_dir()
&& path
.file_name()
.is_some_and(|name| name.to_string_lossy().ends_with(run_id_suffix))
})
.unwrap_or_else(|| {
panic!(
"expected run directory for {run_id_suffix} under {}",
runs_dir.display()
)
})
}
/// Return the only run directory currently present under storage.
pub fn single_run_dir(&self) -> PathBuf {
let runs_dir = self.storage_dir.join("runs");
let entries: Vec<_> = std::fs::read_dir(&runs_dir)
.expect("runs directory should exist")
.flatten()
.map(|entry| entry.path())
.filter(|path| path.is_dir())
.collect();
assert_eq!(
entries.len(),
1,
"expected exactly one run directory under {}",
runs_dir.display()
);
entries.into_iter().next().unwrap()
}
}
/// Execute a command and format the output for snapshot testing.