Skip to content

Commit

Permalink
Add is_success & is_failure methods
Browse files Browse the repository at this point in the history
Signed-off-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
  • Loading branch information
MikailBag committed Sep 5, 2022
1 parent edad3da commit eaa34e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kube-client/src/lib.rs
Expand Up @@ -478,7 +478,7 @@ mod test {
let ep = EvictParams::default();
let eres = pods.evict("busybox-kube3", &ep).await?;
assert_eq!(eres.code, 201); // created
assert_eq!(eres.status, Some(StatusSummary::Success));
assert!(eres.is_success());

Ok(())
}
Expand Down
18 changes: 16 additions & 2 deletions kube-core/src/response.rs
Expand Up @@ -2,8 +2,6 @@
use serde::{Deserialize, Serialize};

/// A Kubernetes status object
///
/// Equivalent to Status in k8s-openapi except we have have simplified options
#[derive(Serialize, Deserialize, Debug)]
pub struct Status {
/// Status of the operation
Expand Down Expand Up @@ -69,6 +67,22 @@ impl Status {
self.details = Some(details);
self
}

/// Checks if this `Status` represents success
///
/// Note that it is possible for `Status` to be in indeterminate state
/// when both `is_success` and `is_failure` return false.
pub fn is_success(&self) -> bool {
self.status == Some(StatusSummary::Success)
}

/// Checks if this `Status` represents failure
///
/// Note that it is possible for `Status` to be in indeterminate state
/// when both `is_success` and `is_failure` return false.
pub fn is_failure(&self) -> bool {
self.status == Some(StatusSummary::Failure)
}
}

/// Overall status of the operation - whether it succeeded or not
Expand Down

0 comments on commit eaa34e4

Please sign in to comment.