You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

use super::*;
#[inline] fn gen_meta() -> StoreMetadata
{
StoreMetadata{
name: "test".to_string(),
root: "./test/db".to_owned().into(),
}
}
#[test]
fn create()
{
let store = Store::new(gen_meta());
let freeze = store.into_freeze();
let _ = freeze.into_new();
}
#[test]
fn entries()
{
let mut store = Store::new(gen_meta());
macro_rules! build {
() => {
EntryBuilder::new()
.name("Hello")
.desc("Desc")
.tags(&["Tag1", "Tag2", "Tag3"])
.hash(sha256::compute_slice(b"hello world"))
.location(Path::new("test_file"))
};
}
let entry = build!()
.build().expect("Failed to build entry");
println!("Entry: {:#?}", entry);
let entry = store.insert(entry).clone();
store.insert(build!()
.hash(sha256::compute_slice("something else"))
.name("Entry 2")
.build().expect("Failed to build entry 2"));
println!("Entry ref: {:#?}", entry);
println!("Store: {:#?}", store);
let freeze = store.freeze();
println!("Frozen: {:#?}", freeze);
let store2 = Store::unfreeze(&freeze);
assert_eq!(store2.tag_search("Tag2").filter(|x| x.name() == entry.name()).next().unwrap().hash(), entry.hash());
assert_eq!(store.tag_search_any(vec!["Tag2", "Tag3"]).filter(|x| x.name() == entry.name()).next().unwrap().hash(), entry.hash());
assert_eq!(store2.tag_search_all(vec!["Tag1", "Tag3"]).filter(|x| x.name() == entry.name()).next().unwrap().hash(), entry.hash());
assert!(store.tag_search_all(vec!["Tag1", "Nope"]).next().is_none());
let json = serde_json::to_string_pretty(&freeze).unwrap();
println!("Freeze serialised ({} bytes): '{}'", json.len(), json);
let ufreeze: Freeze = serde_json::from_str(json.as_str()).unwrap();
assert_eq!(ufreeze, freeze);
println!("Freeze unseralised as store: {:#?}", ufreeze.into_new());
}