Skip to content

Commit

Permalink
tests: add unit test case for service/src/upgrade.rs
Browse files Browse the repository at this point in the history
test type transformation between struct FailoverPolicy and String/&str
  • Loading branch information
hijackthe2 committed Oct 24, 2023
1 parent acb689f commit b0408fe
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion service/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::Result;
pub enum UpgradeMgrError {}

/// FUSE fail-over policies.
#[derive(PartialEq, Eq)]
#[derive(PartialEq, Eq, Debug)]
pub enum FailoverPolicy {
/// Flush pending requests.
Flush,
Expand Down Expand Up @@ -86,3 +86,41 @@ pub mod fusedev_upgrade {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_failover_policy() {
assert_eq!(
FailoverPolicy::try_from("flush").unwrap(),
FailoverPolicy::Flush
);
assert_eq!(
FailoverPolicy::try_from("resend").unwrap(),
FailoverPolicy::Resend
);

let strs = vec!["flash", "Resend"];
for s in strs.clone().into_iter() {
assert!(FailoverPolicy::try_from(s).is_err());
}

let str = String::from("flush");
assert_eq!(
FailoverPolicy::try_from(&str).unwrap(),
FailoverPolicy::Flush
);
let str = String::from("resend");
assert_eq!(
FailoverPolicy::try_from(&str).unwrap(),
FailoverPolicy::Resend
);

let strings: Vec<String> = strs.into_iter().map(|s| s.to_owned()).collect();
for s in strings.iter() {
assert!(FailoverPolicy::try_from(s).is_err());
}
}
}

0 comments on commit b0408fe

Please sign in to comment.