nanocld_client/
node.rs

1use nanocl_error::http_client::HttpClientResult;
2
3use nanocl_stubs::node::Node;
4
5use super::http_client::NanocldClient;
6
7impl NanocldClient {
8  /// ## Default path for nodes
9  const NODE_PATH: &'static str = "/nodes";
10
11  /// List existing nodes in the system
12  ///
13  /// ## Example
14  ///
15  /// ```no_run,ignore
16  /// use nanocld_client::NanocldClient;
17  ///
18  /// let client = NanocldClient::connect_to("http://localhost:8585", None);
19  /// let res = client.list_node().await;
20  /// ```
21  ///
22  pub async fn list_node(&self) -> HttpClientResult<Vec<Node>> {
23    let res = self.send_get(Self::NODE_PATH, None::<String>).await?;
24    Self::res_json(res).await
25  }
26}
27
28#[cfg(test)]
29mod tests {
30  use crate::ConnectOpts;
31
32  use super::*;
33
34  #[ntex::test]
35  async fn basic() {
36    let client = NanocldClient::connect_to(&ConnectOpts {
37      url: "http://nanocl.internal:8585".into(),
38      ..Default::default()
39    })
40    .expect("Failed to create a nanocl client");
41    let node = client.list_node().await;
42    assert!(node.is_ok());
43  }
44}