tests pass

master
Bel LaPointe 2025-11-11 17:29:31 -07:00
parent 3c64bb27de
commit 90de4a0cfd
1 changed files with 39 additions and 4 deletions

View File

@ -162,15 +162,12 @@ impl File {
let persisted = serde_json::to_string(&persisted).unwrap();
let persisted = persisted.as_str();
let persisted: serde_json::Value = serde_json::from_str(&persisted).unwrap();
eprintln!("PERSISTED | {:?}", &persisted);
let stage = self.stage()?;
let stage = serde_json::to_string(&stage).unwrap();
let stage: serde_json::Value = serde_json::from_str(stage.as_str()).unwrap();
eprintln!(" STAGE | {:?}", &stage);
let patches = json_patch::diff(&persisted, &stage);
eprintln!(" PATCHES | {:?}", &patches);
let deltas: Vec<Delta> = patches
.iter()
.map(|patch| patch.clone())
@ -260,7 +257,7 @@ mod test_file {
}
#[test]
fn test_file_empty_stage() {
fn test_file_empty_stage_fills_events() {
tests::with_dir(|d| {
tests::write_file(&d, "plain", "[hello, world]");
@ -281,6 +278,44 @@ mod test_file {
tests::file_contains(&d, "plain", "- hello\n- world");
});
}
#[test]
fn test_file_persist_empty_drains_events() {
tests::with_dir(|d| {
tests::write_file(&d, "plain", "[]");
tests::write_file(
&d,
".plain.host_a",
r#"
{"ts":1, "patch":{"op":"replace", "path":"", "value": ["initial"]}}
{"ts":3, "patch":{"op":"add", "path":"/-", "value": {"k":"v"}}}
"#,
);
tests::write_file(
&d,
".plain.host_b",
r#"
{"ts":2, "patch":{"op":"add", "path":"/-", "value": 1}}
"#,
);
let f = File::new(&d.path().join("plain").to_str().unwrap().to_string());
assert_eq!(3, 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!(0, f.stage().unwrap().len());
tests::file_contains(&d, "plain", "[]");
f.stage_persisted().unwrap();
assert_eq!(6, f.events().unwrap().0.len());
assert_eq!(0, f.stage().unwrap().len());
tests::file_contains(&d, "plain", "[]");
});
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]