fix(mitigate): fix non-deterministic test

This commit is contained in:
Federico Terzi 2021-05-27 23:16:53 +02:00
parent 6ee301c6e1
commit b5786b6530

View File

@ -66,7 +66,7 @@ mod load;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::{fs::create_dir_all, path::{Path}}; use std::{collections::HashMap, fs::create_dir_all, path::{Path}};
use super::*; use super::*;
use include_dir::{include_dir, Dir}; use include_dir::{include_dir, Dir};
@ -101,6 +101,12 @@ mod tests {
action(&legacy_path, &expected_path); action(&legacy_path, &expected_path);
} }
fn to_sorted_list<T>(hash: HashMap<String, T>) -> Vec<(String, T)> {
let mut tuples: Vec<(String, T)> = hash.into_iter().map(|(k, v)| (k, v)).collect();
tuples.sort_by_key(|(k, _)| k.clone());
tuples
}
static SIMPLE_CASE: Dir = include_dir!("test/simple"); static SIMPLE_CASE: Dir = include_dir!("test/simple");
static BASE_CASE: Dir = include_dir!("test/base"); static BASE_CASE: Dir = include_dir!("test/base");
@ -115,7 +121,7 @@ mod tests {
assert_eq!(converted_files.len(), expected_files.len()); assert_eq!(converted_files.len(), expected_files.len());
for (file, content) in converted_files { for (file, content) in to_sorted_list(converted_files) {
assert_peq!(&content, expected_files.get(&file).unwrap()); assert_peq!(&content, expected_files.get(&file).unwrap());
} }
}); });