Skip to content

Commit

Permalink
ndc-test: replay test folders in alphabetical order (#149)
Browse files Browse the repository at this point in the history
* ndc-test: replay test folders in alphabet order

* Separate warnings from critial errors

---------

Co-authored-by: Phil Freeman <phil@hasura.io>
  • Loading branch information
hgiasac and paf31 authored Jun 7, 2024
1 parent aa8ad48 commit aae78ce
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ndc-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ pub async fn test_snapshots_in_directory_with<
snapshots_dir: PathBuf,
f: impl Fn(Req) -> F,
) {
match std::fs::read_dir(snapshots_dir) {
Ok(dir) => {
for entry in dir {
let entry = entry.expect("Error reading snapshot directory entry");

if snapshots_dir.exists() {
let entries =
read_dir_sorted_by_name(snapshots_dir).expect("Unable to read snapshot directory");
for entry in entries {
if entry.metadata().is_ok_and(|md| md.is_dir()) {
test!(
entry.file_name().to_str().unwrap_or("{unknown}"),
reporter,
Expand All @@ -168,10 +168,20 @@ pub async fn test_snapshots_in_directory_with<
);
}
}
Err(e) => println!("Warning: a snapshot folder could not be found: {e}"),
} else {
println!("Warning: a snapshot folder could not be found: {snapshots_dir:?}");
}
}

// Read directory and sort inner files by alphabet
fn read_dir_sorted_by_name(snapshots_dir: PathBuf) -> std::io::Result<Vec<std::fs::DirEntry>> {
let mut paths: Vec<_> =
std::fs::read_dir(snapshots_dir)?.collect::<std::io::Result<Vec<_>>>()?;
paths.sort_by_key(std::fs::DirEntry::path);

Ok(paths)
}

#[derive(Debug, Clone)]
pub struct ReportConfiguration {
pub samples: u32,
Expand Down

0 comments on commit aae78ce

Please sign in to comment.