Skip to content

Commit e224745

Browse files
committed
test(analysis): sort results to make them comparable between runs
1 parent d0660a1 commit e224745

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

modules/analysis/src/endpoints/tests/latest_filters.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use super::req::*;
22
use crate::test::caller;
33
use rstest::*;
4-
use serde_json::json;
4+
use serde_json::{Value, json};
5+
use std::cmp;
56
use test_context::test_context;
67
use trustify_test_context::{TrustifyContext, subset::ContainsSubset};
78

@@ -50,7 +51,9 @@ async fn resolve_rh_variant_latest_filter_container_cdx(
5051
let _response = app.req(Req::default()).await?;
5152
}
5253

53-
let response = app.req(req).await?;
54+
let mut response = app.req(req).await?;
55+
56+
sort(&mut response["items"]);
5457

5558
log::info!("{response:#?}");
5659
assert_eq!(total, response["total"]);
@@ -528,3 +531,31 @@ async fn test_tc2578(
528531

529532
Ok(())
530533
}
534+
535+
/// Sort all entries by document_id, then published, then name.
536+
///
537+
/// This includes recursive sorting of ancestors/descendants.
538+
fn sort(json: &mut Value) {
539+
let Value::Array(items) = json else {
540+
return;
541+
};
542+
543+
fn by_str(name: &str, a: &Value, b: &Value) -> cmp::Ordering {
544+
a[name].as_str().cmp(&b[name].as_str())
545+
}
546+
547+
// sort list
548+
549+
items.sort_unstable_by(|a, b| {
550+
by_str("document_id", a, b)
551+
.then_with(|| by_str("published", a, b))
552+
.then_with(|| by_str("name", a, b))
553+
});
554+
555+
// now sort child entries
556+
557+
for item in items {
558+
sort(&mut item["ancestors"]);
559+
sort(&mut item["descendants"]);
560+
}
561+
}

0 commit comments

Comments
 (0)