Skip to content

Commit

Permalink
[ISSUE #535]✅Add test case for CleanupPolicy (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowsoy authored Jun 14, 2024
1 parent d726e0e commit 5542741
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion rocketmq-common/src/common/attribute/cleanup_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl fmt::Display for CleanupPolicy {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct ParseCleanupPolicyError;

impl fmt::Display for ParseCleanupPolicyError {
Expand All @@ -54,3 +54,31 @@ impl FromStr for CleanupPolicy {
}
}
}

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

#[test]
fn cleanup_policy_display() {
assert_eq!(CleanupPolicy::DELETE.to_string(), "DELETE");
assert_eq!(CleanupPolicy::COMPACTION.to_string(), "COMPACTION");
}

#[test]
fn cleanup_policy_from_str() {
assert_eq!("DELETE".parse(), Ok(CleanupPolicy::DELETE));
assert_eq!("COMPACTION".parse(), Ok(CleanupPolicy::COMPACTION));
}

#[test]
fn cleanup_policy_from_str_case_insensitive() {
assert_eq!("delete".parse(), Ok(CleanupPolicy::DELETE));
assert_eq!("compaction".parse(), Ok(CleanupPolicy::COMPACTION));
}

#[test]
fn cleanup_policy_from_str_invalid() {
assert!("invalid".parse::<CleanupPolicy>().is_err());
}
}

0 comments on commit 5542741

Please sign in to comment.