nomad_client_rs/api/
status.rs

1use reqwest::Method;
2
3use crate::{ClientError, NomadClient};
4
5impl NomadClient {
6    pub async fn status_get_leader(&self) -> Result<String, ClientError> {
7        let req = self.request(Method::GET, "/status/leader");
8
9        self.send::<String>(req).await
10    }
11
12    pub async fn status_get_peers(&self) -> Result<Vec<String>, ClientError> {
13        let req = self.request(Method::GET, "/status/peers");
14
15        self.send::<Vec<String>>(req).await
16    }
17}
18
19#[cfg(test)]
20mod tests {
21    use std::net::SocketAddr;
22
23    use crate::{Config, MTLSConfig, NomadClient};
24
25    #[tokio::test]
26    async fn status_get_leader_should_return_socket_address_of_leader() {
27        let client = NomadClient::default();
28
29        match client.status_get_leader().await {
30            Ok(url_string) => match url_string.parse::<SocketAddr>() {
31                Ok(_) => assert!(true),
32                Err(e) => panic!("{:#?}", e),
33            },
34
35            Err(e) => panic!("{:#?}", e),
36        }
37    }
38
39    #[tokio::test]
40    async fn status_get_peers_should_return_socket_address_of_peers() {
41        let client = NomadClient::default();
42
43        match client.status_get_peers().await {
44            Ok(peers) => assert!(!peers.is_empty()),
45            Err(e) => panic!("{:#?}", e),
46        }
47    }
48
49    /*    #[tokio::test]
50    async fn mtls_test() {
51        let mut config = Config::default();
52        config.base_url = "https://localhost".into();
53        config.mtls = Some(MTLSConfig::new("cli.pem","/cli-key.pem"));
54
55        let client = NomadClient::new(config);
56
57        match client.status_get_peers().await {
58            Ok(peers) => assert!(!peers.is_empty()),
59            Err(e) => panic!("{:#?}", e),
60        }
61    }*/
62}