add basic re-load test
This commit is contained in:
parent
99e15dac10
commit
88688f8a68
2 changed files with 17 additions and 2 deletions
|
@ -86,7 +86,8 @@ impl Index {
|
|||
.read_to_string()
|
||||
.context(format!("reading index file contents from {}", index_file_path.as_str()))?;
|
||||
|
||||
let index: Index = serde_json::from_str(&index_text).context(format!("cannot read index from: {}", index_text))?;
|
||||
let index: Index =
|
||||
serde_json::from_str(&index_text).context(format!("cannot read index from: {}", index_file_path.as_str()))?;
|
||||
Ok(index)
|
||||
}
|
||||
|
||||
|
@ -115,6 +116,7 @@ impl Index {
|
|||
mod must {
|
||||
use crate::index::Index;
|
||||
use anyhow::Result;
|
||||
|
||||
use vfs::{MemoryFS, VfsPath};
|
||||
|
||||
#[test]
|
||||
|
@ -131,4 +133,17 @@ mod must {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn be_same_when_loaded_from_disk() -> Result<()> {
|
||||
let repository_path: VfsPath = MemoryFS::new().into();
|
||||
let mut original = Index::new()?;
|
||||
|
||||
original.save(&repository_path)?;
|
||||
let loaded = Index::load(&repository_path)?;
|
||||
|
||||
assert_eq!(original, loaded);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ mod io;
|
|||
pub mod item;
|
||||
mod lock;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
pub struct Index {
|
||||
newest_items_by_source_path: HashMap<String, IndexItem>,
|
||||
items_by_file_id: HashMap<ItemId, IndexItem>,
|
||||
|
|
Loading…
Reference in a new issue