diff --git a/service/src/upgrade.rs b/service/src/upgrade.rs index 2503d13ee34..7c55433af91 100644 --- a/service/src/upgrade.rs +++ b/service/src/upgrade.rs @@ -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, @@ -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 = strs.into_iter().map(|s| s.to_owned()).collect(); + for s in strings.iter() { + assert!(FailoverPolicy::try_from(s).is_err()); + } + } +}