Skip to main content

wot_search_tests/
lib.rs

1//! Generic tests for implementations of the [`wot_network::search`] traits
2//! [`ResidualNetworkTrait`](wot_network::search::ResidualNetworkTrait) and
3//! [`WotSearchTrait`](wot_network::search::WotSearchTrait).
4//!
5//! This crate includes some test configurations and WoT network graphs to run them on.
6//!
7//! The tests in this crate can be run by implementers of the [`wot_network::search`] traits like
8//! this:
9//!
10//! `test_wot_search::<WotSearchImplementation>("<path_to>/tests/flow/")?;`
11
12pub mod flow;
13pub mod model;
14pub mod test_files;
15
16#[cfg(all(feature = "log", not(feature = "tracing")))]
17mod internal_prelude {
18    #[allow(unused_imports)]
19    pub use log::{debug, error, info, trace, warn};
20}
21
22#[cfg(all(feature = "tracing", not(feature = "log")))]
23mod internal_prelude {
24    #[allow(unused_imports)]
25    pub use tracing::{debug, error, info, trace, warn};
26}
27
28#[cfg(all(feature = "log", feature = "tracing"))]
29compile_error!(
30    "feature \"log\" and feature \"tracing\" are enabled at the same time for 'wot-search-tests'. Falling back to log"
31);
32
33enum SearchTestError {
34    BadAmount,
35    BadPathCount,
36}
37
38/// Compare an expected path from the test configuration with a path search result.
39fn compare_paths(expected: &[String], found: &wot_network::search::Path) {
40    // Lengths should match
41    assert_eq!(
42        expected.len(),
43        found.length(),
44        "Length mismatch in compare_paths. Comparing paths {expected:#?} and {found:#?}"
45    );
46
47    // Each node should match (comparing certificate names)
48    let matching = std::iter::zip(expected, found.certificates()).all(|(e, f)| e == &f.to_string());
49
50    if !matching {
51        panic!(
52            "expected {:?} vs. found path {:?}",
53            expected,
54            found.certificates()
55        );
56    }
57}