Skip to content

Commit 1c45ee2

Browse files
committed
test: add unit tests for logrustate state database
1 parent c6f7c0a commit 1c45ee2

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/state.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,28 @@ impl StateDB {
128128
}
129129
}
130130
}
131+
132+
#[cfg(test)]
133+
mod tests {
134+
use super::*;
135+
136+
#[test]
137+
fn test_should_rotate_unseen_path() {
138+
let db = StateDB {
139+
path: "dummy".to_string(),
140+
entries: HashMap::new(),
141+
};
142+
assert!(db.should_rotate("/var/log/test.log", "daily"));
143+
}
144+
145+
#[test]
146+
fn test_should_rotate_recent_path() {
147+
let mut entries = HashMap::new();
148+
entries.insert("/var/log/test.log".to_string(), Local::now().naive_local());
149+
let db = StateDB {
150+
path: "dummy".to_string(),
151+
entries,
152+
};
153+
assert!(!db.should_rotate("/var/log/test.log", "daily"));
154+
}
155+
}

0 commit comments

Comments
 (0)