✨ feat(retention): implement retention policy configuration
- define struct for retention policy with message age and label generation - add methods to create, access, and modify retention policies - implement default values, cloning, equality, and debug formatting
This commit is contained in:
committed by
Jeremiah Russell
parent
32db9cb51a
commit
1448c791d9
@@ -19,7 +19,7 @@ pub use message_age::MessageAge;
|
||||
/// // Create a retention policy without auto-generated labels
|
||||
/// let policy = Retention::new(MessageAge::Years(1), false);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Retention {
|
||||
age: MessageAge,
|
||||
generate_label: bool,
|
||||
@@ -70,6 +70,7 @@ impl Retention {
|
||||
/// let policy = Retention::new(MessageAge::Days(30), true);
|
||||
/// assert_eq!(policy.age(), &MessageAge::Days(30));
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn age(&self) -> &MessageAge {
|
||||
&self.age
|
||||
}
|
||||
@@ -90,6 +91,7 @@ impl Retention {
|
||||
/// let policy = Retention::new(MessageAge::Days(30), false);
|
||||
/// assert_eq!(policy.generate_label(), false);
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn generate_label(&self) -> bool {
|
||||
self.generate_label
|
||||
}
|
||||
@@ -120,7 +122,7 @@ mod tests {
|
||||
let retention = Retention::new(age.clone(), true);
|
||||
|
||||
assert_eq!(retention.age(), &age);
|
||||
assert_eq!(retention.generate_label(), true);
|
||||
assert!(retention.generate_label());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -129,7 +131,7 @@ mod tests {
|
||||
let retention = Retention::new(age.clone(), false);
|
||||
|
||||
assert_eq!(retention.age(), &age);
|
||||
assert_eq!(retention.generate_label(), false);
|
||||
assert!(!retention.generate_label());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -137,13 +139,13 @@ mod tests {
|
||||
let age = MessageAge::Months(6);
|
||||
let mut retention = Retention::new(age.clone(), false);
|
||||
|
||||
assert_eq!(retention.generate_label(), false);
|
||||
assert!(!retention.generate_label());
|
||||
|
||||
retention.set_generate_label(true);
|
||||
assert_eq!(retention.generate_label(), true);
|
||||
assert!(retention.generate_label());
|
||||
|
||||
retention.set_generate_label(false);
|
||||
assert_eq!(retention.generate_label(), false);
|
||||
assert!(!retention.generate_label());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -178,7 +180,7 @@ mod tests {
|
||||
let default = Retention::default();
|
||||
|
||||
assert_eq!(default.age(), &MessageAge::Years(5));
|
||||
assert_eq!(default.generate_label(), true);
|
||||
assert!(default.generate_label());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -193,10 +195,10 @@ mod tests {
|
||||
assert_eq!(retention_months.age().period_type(), "months");
|
||||
assert_eq!(retention_years.age().period_type(), "years");
|
||||
|
||||
assert_eq!(retention_days.generate_label(), true);
|
||||
assert_eq!(retention_weeks.generate_label(), false);
|
||||
assert_eq!(retention_months.generate_label(), true);
|
||||
assert_eq!(retention_years.generate_label(), false);
|
||||
assert!(retention_days.generate_label());
|
||||
assert!(!retention_weeks.generate_label());
|
||||
assert!(retention_months.generate_label());
|
||||
assert!(!retention_years.generate_label());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user