mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-07 08:27:12 +00:00
Refactor run CLI tests to use snapshots
This commit is contained in:
parent
6046203e42
commit
0346edd112
3 changed files with 626 additions and 420 deletions
|
|
@ -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
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue