| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | use topcoat::internal::inventory; |
| 6 | use topcoat::router::{Layer, Layout, Page, Route}; |
| 7 | |
| 8 | fn listed() -> String { |
| 9 | let mut lines: Vec<String> = Vec::new(); |
| 10 | for route in inventory::iter::<&'static dyn Route>() { |
| 11 | lines.push(format!("route {} {:?}", route.path(), route.methods())); |
| 12 | } |
| 13 | for page in inventory::iter::<&'static dyn Page>() { |
| 14 | lines.push(format!("page {} {:?}", page.path(), page.methods())); |
| 15 | } |
| 16 | for layout in inventory::iter::<&'static dyn Layout>() { |
| 17 | lines.push(format!("layout {}", layout.path())); |
| 18 | } |
| 19 | for layer in inventory::iter::<&'static dyn Layer>() { |
| 20 | lines.push(format!("layer {:?}", layer.path().map(ToString::to_string))); |
| 21 | } |
| 22 | lines.sort(); |
| 23 | lines.join("\n") + "\n" |
| 24 | } |
| 25 | |
| 26 | #[test] |
| 27 | fn discovered_routes_match_the_snapshot() { |
| 28 | let path = concat!(env!("CARGO_MANIFEST_DIR"), "/src/routes.snap"); |
| 29 | let now = listed(); |
| 30 | if std::env::var_os("FORGE_BLESS").is_some() { |
| 31 | std::fs::write(path, &now).unwrap(); |
| 32 | } |
| 33 | let want = std::fs::read_to_string(path).unwrap_or_default(); |
| 34 | assert!(now == want, "discovered routes differ from src/routes.snap"); |
| 35 | } |