tests pass
parent
3c64bb27de
commit
90de4a0cfd
|
|
@ -162,15 +162,12 @@ impl File {
|
||||||
let persisted = serde_json::to_string(&persisted).unwrap();
|
let persisted = serde_json::to_string(&persisted).unwrap();
|
||||||
let persisted = persisted.as_str();
|
let persisted = persisted.as_str();
|
||||||
let persisted: serde_json::Value = serde_json::from_str(&persisted).unwrap();
|
let persisted: serde_json::Value = serde_json::from_str(&persisted).unwrap();
|
||||||
eprintln!("PERSISTED | {:?}", &persisted);
|
|
||||||
|
|
||||||
let stage = self.stage()?;
|
let stage = self.stage()?;
|
||||||
let stage = serde_json::to_string(&stage).unwrap();
|
let stage = serde_json::to_string(&stage).unwrap();
|
||||||
let stage: serde_json::Value = serde_json::from_str(stage.as_str()).unwrap();
|
let stage: serde_json::Value = serde_json::from_str(stage.as_str()).unwrap();
|
||||||
eprintln!(" STAGE | {:?}", &stage);
|
|
||||||
|
|
||||||
let patches = json_patch::diff(&persisted, &stage);
|
let patches = json_patch::diff(&persisted, &stage);
|
||||||
eprintln!(" PATCHES | {:?}", &patches);
|
|
||||||
let deltas: Vec<Delta> = patches
|
let deltas: Vec<Delta> = patches
|
||||||
.iter()
|
.iter()
|
||||||
.map(|patch| patch.clone())
|
.map(|patch| patch.clone())
|
||||||
|
|
@ -260,7 +257,7 @@ mod test_file {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_empty_stage() {
|
fn test_file_empty_stage_fills_events() {
|
||||||
tests::with_dir(|d| {
|
tests::with_dir(|d| {
|
||||||
tests::write_file(&d, "plain", "[hello, world]");
|
tests::write_file(&d, "plain", "[hello, world]");
|
||||||
|
|
||||||
|
|
@ -281,6 +278,44 @@ mod test_file {
|
||||||
tests::file_contains(&d, "plain", "- hello\n- world");
|
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)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue