✨ 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
|
/// // Create a retention policy without auto-generated labels
|
||||||
/// let policy = Retention::new(MessageAge::Years(1), false);
|
/// let policy = Retention::new(MessageAge::Years(1), false);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Retention {
|
pub struct Retention {
|
||||||
age: MessageAge,
|
age: MessageAge,
|
||||||
generate_label: bool,
|
generate_label: bool,
|
||||||
@@ -70,6 +70,7 @@ impl Retention {
|
|||||||
/// let policy = Retention::new(MessageAge::Days(30), true);
|
/// let policy = Retention::new(MessageAge::Days(30), true);
|
||||||
/// assert_eq!(policy.age(), &MessageAge::Days(30));
|
/// assert_eq!(policy.age(), &MessageAge::Days(30));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn age(&self) -> &MessageAge {
|
pub fn age(&self) -> &MessageAge {
|
||||||
&self.age
|
&self.age
|
||||||
}
|
}
|
||||||
@@ -90,6 +91,7 @@ impl Retention {
|
|||||||
/// let policy = Retention::new(MessageAge::Days(30), false);
|
/// let policy = Retention::new(MessageAge::Days(30), false);
|
||||||
/// assert_eq!(policy.generate_label(), false);
|
/// assert_eq!(policy.generate_label(), false);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn generate_label(&self) -> bool {
|
pub fn generate_label(&self) -> bool {
|
||||||
self.generate_label
|
self.generate_label
|
||||||
}
|
}
|
||||||
@@ -120,7 +122,7 @@ mod tests {
|
|||||||
let retention = Retention::new(age.clone(), true);
|
let retention = Retention::new(age.clone(), true);
|
||||||
|
|
||||||
assert_eq!(retention.age(), &age);
|
assert_eq!(retention.age(), &age);
|
||||||
assert_eq!(retention.generate_label(), true);
|
assert!(retention.generate_label());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -129,7 +131,7 @@ mod tests {
|
|||||||
let retention = Retention::new(age.clone(), false);
|
let retention = Retention::new(age.clone(), false);
|
||||||
|
|
||||||
assert_eq!(retention.age(), &age);
|
assert_eq!(retention.age(), &age);
|
||||||
assert_eq!(retention.generate_label(), false);
|
assert!(!retention.generate_label());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -137,13 +139,13 @@ mod tests {
|
|||||||
let age = MessageAge::Months(6);
|
let age = MessageAge::Months(6);
|
||||||
let mut retention = Retention::new(age.clone(), false);
|
let mut retention = Retention::new(age.clone(), false);
|
||||||
|
|
||||||
assert_eq!(retention.generate_label(), false);
|
assert!(!retention.generate_label());
|
||||||
|
|
||||||
retention.set_generate_label(true);
|
retention.set_generate_label(true);
|
||||||
assert_eq!(retention.generate_label(), true);
|
assert!(retention.generate_label());
|
||||||
|
|
||||||
retention.set_generate_label(false);
|
retention.set_generate_label(false);
|
||||||
assert_eq!(retention.generate_label(), false);
|
assert!(!retention.generate_label());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -169,8 +171,8 @@ mod tests {
|
|||||||
let retention4 = Retention::new(MessageAge::Days(30), false);
|
let retention4 = Retention::new(MessageAge::Days(30), false);
|
||||||
|
|
||||||
assert_eq!(retention1, retention2);
|
assert_eq!(retention1, retention2);
|
||||||
assert_ne!(retention1, retention3); // different age
|
assert_ne!(retention1, retention3); // different age
|
||||||
assert_ne!(retention1, retention4); // different generate_label
|
assert_ne!(retention1, retention4); // different generate_label
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -178,7 +180,7 @@ mod tests {
|
|||||||
let default = Retention::default();
|
let default = Retention::default();
|
||||||
|
|
||||||
assert_eq!(default.age(), &MessageAge::Years(5));
|
assert_eq!(default.age(), &MessageAge::Years(5));
|
||||||
assert_eq!(default.generate_label(), true);
|
assert!(default.generate_label());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -193,10 +195,10 @@ mod tests {
|
|||||||
assert_eq!(retention_months.age().period_type(), "months");
|
assert_eq!(retention_months.age().period_type(), "months");
|
||||||
assert_eq!(retention_years.age().period_type(), "years");
|
assert_eq!(retention_years.age().period_type(), "years");
|
||||||
|
|
||||||
assert_eq!(retention_days.generate_label(), true);
|
assert!(retention_days.generate_label());
|
||||||
assert_eq!(retention_weeks.generate_label(), false);
|
assert!(!retention_weeks.generate_label());
|
||||||
assert_eq!(retention_months.generate_label(), true);
|
assert!(retention_months.generate_label());
|
||||||
assert_eq!(retention_years.generate_label(), false);
|
assert!(!retention_years.generate_label());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user