all tests pass woo

master
Bel LaPointe 2025-12-01 17:23:23 -07:00
parent 4ad0b7d2ff
commit bb64b87752
1 changed files with 18 additions and 27 deletions

View File

@ -153,7 +153,7 @@ impl File {
Events::new(&self.file)
}
pub fn persist_unpersisted_stage(&self) -> Result<(), String> {
pub fn persist_stage(&self) -> Result<(), String> {
let old_snapshot = self.events()?.last_snapshot();
let stage_mod_time = std::fs::metadata(&self.file)
.unwrap()
@ -176,17 +176,6 @@ impl File {
Ok(())
}
pub fn persist_stage(&self) -> Result<(), String> {
self.persist_unpersisted_stage()?;
let persisted = self.events()?.snapshot()?;
let stage = self.stage()?;
self.persist_delta(persisted, stage)?;
Ok(())
}
pub fn persist_delta(&self, before: Vec<Task>, after: Vec<Task>) -> Result<(), String> {
self.persist_delta_at(before, after, Delta::now_time())
}
@ -311,7 +300,7 @@ mod test_file {
tests::file_contains(&d, "plain", "world");
f.stage_persisted().unwrap();
assert_eq!(2, f.events().unwrap().0.len());
assert_eq!(3, f.events().unwrap().0.len());
assert_eq!(2, f.stage().unwrap().len());
tests::file_contains(&d, "plain", "- hello\n- world");
});
@ -327,6 +316,7 @@ mod test_file {
r#"
{"ts":1, "op":"Add", "task": "initial"}
{"ts":3, "op":"Add", "task": {"k":"v"}}
{"ts":3, "op":"Snapshot", "task": null, "tasks": ["initial", 1, {"k":"v"}]}
"#,
);
tests::write_file(
@ -339,12 +329,12 @@ mod test_file {
let f = File::new(&d.path().join("plain").to_str().unwrap().to_string());
assert_eq!(3, f.events().unwrap().0.len());
assert_eq!(4, f.events().unwrap().0.len());
assert_eq!(0, f.stage().unwrap().len());
tests::file_contains(&d, "plain", "[]");
f.persist_stage().unwrap();
assert_eq!(6, f.events().unwrap().0.len());
assert_eq!(7, f.events().unwrap().0.len());
assert_eq!(0, f.stage().unwrap().len());
tests::file_contains(&d, "plain", "[]");
@ -356,7 +346,7 @@ mod test_file {
f.events().unwrap().snapshot().unwrap(),
);
assert_eq!(
6,
8,
f.events().unwrap().0.len(),
"{:?}",
f.events().unwrap().0
@ -383,12 +373,13 @@ mod test_file {
".plain.host_b",
r#"
{"ts":2, "op":"Add", "task": 1}
{"ts":2, "op":"Snapshot", "task": null, "tasks": ["initial", 1]}
"#,
);
let f = File::new(&d.path().join("plain").to_str().unwrap().to_string());
assert_eq!(3, f.events().unwrap().0.len());
assert_eq!(4, f.events().unwrap().0.len());
assert_eq!(2, f.stage().unwrap().len());
tests::file_contains(&d, "plain", "- initial\n- 1");
@ -398,14 +389,14 @@ mod test_file {
tests::file_contains(&d, "plain", "- initial\n- 1");
f.stage_persisted().unwrap();
assert_eq!(4, f.events().unwrap().0.len());
assert_eq!(2, f.stage().unwrap().len());
tests::file_contains(&d, "plain", "- initial\n- 1");
assert_eq!(5, f.events().unwrap().0.len());
assert_eq!(3, f.stage().unwrap().len());
tests::file_contains(&d, "plain", "- initial\n- 1\n- k: v");
});
}
#[test]
fn test_persist_unpersisted_stage() {
fn test_persist_stage() {
tests::with_dir(|d| {
tests::write_file(&d, "plain", "- old\n- new");
tests::write_file(
@ -415,10 +406,9 @@ mod test_file {
r#"
{{"ts":1, "op":"Add", "task": "removed"}}
{{"ts":2, "op":"Add", "task": "old"}}
{{"ts":{}, "op":"Add", "task": "was enqueued for persistence but obv removed"}}
{{"ts":{}, "op":"Add", "task": "will be enqueued for persistence"}}
{{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed", "old"]}}
{{"ts":{}, "op":"Add", "task": "persisted but not snapshotted"}}
"#,
Delta::now_time() - 50,
Delta::now_time() + 50,
)
.as_str(),
@ -433,7 +423,7 @@ mod test_file {
f.persist_stage().unwrap();
assert_eq!(
7,
6,
f.events().unwrap().0.len(),
"events: {:?}",
f.events().unwrap()
@ -448,9 +438,10 @@ mod test_file {
"{:?}",
f.events().unwrap().0
);
assert_eq!(2, f.stage().unwrap().len(), "{:?}", f.stage().unwrap());
assert_eq!(3, f.stage().unwrap().len(), "{:?}", f.stage().unwrap());
tests::file_contains(&d, "plain", "new");
tests::file_contains(&d, "plain", "old");
tests::file_contains(&d, "plain", "persisted but not snapshotted");
});
}
@ -535,7 +526,7 @@ mod test_file {
f.stage_persisted().unwrap();
assert_eq!(
1,
2,
f.events().unwrap().0.len(),
"{:?}",
f.events().unwrap().0