Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add upgrade unit test #1440

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test! Is it necessary to test String?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for response and suggestion! I test String type transform here to increase code coverage. Indeed, testing String type is optional.

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());
}
}
}