Skip to content

Commit

Permalink
Added status API calls and tests, added node health API, fixed clippy…
Browse files Browse the repository at this point in the history
… and rustfmt errors
  • Loading branch information
EmilienR committed Jan 8, 2023
1 parent b33fac2 commit 2085039
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub trait Health {
node: &str,
service_name: Option<&str>,
check_id: Option<&str>,
tag: Option<&str>,
options: Option<&QueryOptions>,
) -> Result<(Vec<HealthCheck>, QueryMeta)>;
}
Expand All @@ -77,7 +78,7 @@ impl Health for Client {
if !filter.is_empty() {
filter = format!("({filter}) and ");
}
filter.push_str(&format!("Service.Tags == {tag}"));
filter.push_str(&format!("\"{tag}\" in Service.Tags"));
qoptions.filter = Some(filter);
}
get(&path, &self.config, params, Some(&qoptions))
Expand All @@ -88,6 +89,7 @@ impl Health for Client {
node: &str,
check_id: Option<&str>,
service_name: Option<&str>,
tag: Option<&str>,
options: Option<&QueryOptions>,
) -> Result<(Vec<HealthCheck>, QueryMeta)> {
let mut qoptions = options.map_or_else(QueryOptions::default, |qo| qo.to_owned());
Expand All @@ -108,6 +110,14 @@ impl Health for Client {
filter.push_str(&format!("CheckID == \"{check_id}\""));
qoptions.filter = Some(filter);
}
if let Some(tag) = tag {
let mut filter = qoptions.filter.unwrap_or_default();
if !filter.is_empty() {
filter = format!("({filter}) and ");
}
filter.push_str(&format!("\"{tag}\" in ServiceTags"));
qoptions.filter = Some(filter);
}
get(&path, &self.config, params, Some(&qoptions))
}
}
8 changes: 4 additions & 4 deletions tests/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn health_node_test() {
let system_hostname = hostname::get().unwrap().into_string().unwrap();
// An existing service for a agent in dev mode
let r = client
.node(&system_hostname, Some("serfHealth"), None, None)
.node(&system_hostname, Some("serfHealth"), None, None, None)
.unwrap();
let (services, meta) = (r.0, r.1);
{
Expand All @@ -45,7 +45,7 @@ fn health_node_test() {
}
// A non existing node, should be empty
let r = client
.node("non-existing-node", Some("serfHealth"), None, None)
.node("non-existing-node", Some("serfHealth"), None, None, None)
.unwrap();
let (services, meta) = (r.0, r.1);
{
Expand All @@ -54,7 +54,7 @@ fn health_node_test() {
}
// A non existing check, should be empty
let r = client
.node("localhost", Some("non-existing-check"), None, None)
.node(&system_hostname, Some("non-existing-check"), None, None, None)
.unwrap();
let (services, meta) = (r.0, r.1);
{
Expand All @@ -63,7 +63,7 @@ fn health_node_test() {
}
// A non existing service, should be empty
let r = client
.node("localhost", None, Some("non-existing-service"), None)
.node(&system_hostname, None, Some("non-existing-service"), None, None)
.unwrap();
let (services, meta) = (r.0, r.1);
{
Expand Down

0 comments on commit 2085039

Please sign in to comment.