| 445 | } |
| 446 | |
| 447 | async fn get(router: Router, path: &str) -> (StatusCode, serde_json::Value) { |
| 448 | let response = router |
| 449 | .oneshot(Request::get(path).body(Body::empty()).unwrap()) |
| 450 | .await |
| 451 | .expect("router responds"); |
| 452 | let status = response.status(); |
| 453 | let bytes = response |
| 454 | .into_body() |
| 455 | .collect() |
| 456 | .await |
| 457 | .expect("collect body") |
| 458 | .to_bytes(); |
| 459 | let body = if bytes.is_empty() { |
| 460 | serde_json::Value::Null |
| 461 | } else { |
| 462 | serde_json::from_slice(&bytes).expect("response is valid JSON") |
| 463 | }; |
| 464 | (status, body) |
| 465 | } |
| 466 | |
| 467 | /// Build a router whose state is driven by a `HealthState` we control, |
| 468 | /// so each handler-shape test can pin the exact mapping under test. |