use crate::{state::State, Query};
#[derive(Debug, Eq, PartialEq)]
pub struct Nodes;
impl State for Nodes {}
impl Query<'_, Nodes> {
#[must_use]
pub fn enable_nonvoters(self) -> Self {
self.enable_nonvoters_helper()
}
#[must_use]
pub fn enable_version2(self) -> Self {
self.enable_version_helper(2)
}
}
#[cfg(test)]
#[cfg(any(feature = "percent_encoding", feature = "url"))]
mod tests {
use std::{sync::OnceLock, time::Duration};
use crate::{Connection, Query};
const TEST_CONNECTION_URL: &str = "http://localhost:4001/";
static TEST_CONNECTION: OnceLock<Connection> = OnceLock::new();
fn test_connection() -> &'static Connection {
TEST_CONNECTION.get_or_init(|| {
#[cfg(feature = "url")]
let c = Connection::new(TEST_CONNECTION_URL).unwrap();
#[cfg(not(feature = "url"))]
let c = Connection::new(TEST_CONNECTION_URL);
c
})
}
#[test]
fn monitor_nodes_test() {
let mut q = Query::new(test_connection()).monitor().nodes();
assert_eq!(&q.create_path_with_query(), "/nodes");
q = q.set_pretty();
assert_eq!(&q.create_path_with_query(), "/nodes?pretty");
q = q.enable_nonvoters();
assert_eq!(&q.create_path_with_query(), "/nodes?nonvoters&pretty");
q = q.set_timeout(Duration::from_secs(3).into());
assert_eq!(
&q.create_path_with_query(),
"/nodes?nonvoters&pretty&timeout=3s"
);
}
#[test]
fn monitor_nodes_version2_test() {
let mut q = Query::new(test_connection()).monitor().nodes();
assert_eq!(&q.create_path_with_query(), "/nodes");
q = q.set_pretty();
assert_eq!(&q.create_path_with_query(), "/nodes?pretty");
q = q.enable_version2();
assert_eq!(&q.create_path_with_query(), "/nodes?pretty&ver=2");
}
}