|
1 | 1 | use super::req::*; |
2 | 2 | use crate::test::caller; |
3 | 3 | use rstest::*; |
4 | | -use serde_json::json; |
| 4 | +use serde_json::{Value, json}; |
| 5 | +use std::cmp; |
5 | 6 | use test_context::test_context; |
6 | 7 | use trustify_test_context::{TrustifyContext, subset::ContainsSubset}; |
7 | 8 |
|
@@ -50,7 +51,9 @@ async fn resolve_rh_variant_latest_filter_container_cdx( |
50 | 51 | let _response = app.req(Req::default()).await?; |
51 | 52 | } |
52 | 53 |
|
53 | | - let response = app.req(req).await?; |
| 54 | + let mut response = app.req(req).await?; |
| 55 | + |
| 56 | + sort(&mut response["items"]); |
54 | 57 |
|
55 | 58 | log::info!("{response:#?}"); |
56 | 59 | assert_eq!(total, response["total"]); |
@@ -528,3 +531,31 @@ async fn test_tc2578( |
528 | 531 |
|
529 | 532 | Ok(()) |
530 | 533 | } |
| 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