Now returning duplicate database errors.

This commit is contained in:
Jeff Baskin 2023-06-30 22:38:18 -04:00
parent e73fdbff75
commit c70c006abd
2 changed files with 22 additions and 1 deletions

View File

@ -43,7 +43,10 @@ impl Cache {
pub fn commit(&mut self, data: Store) -> FromCache { pub fn commit(&mut self, data: Store) -> FromCache {
let store = self.data.get_mut(ENTRY).unwrap(); let store = self.data.get_mut(ENTRY).unwrap();
for name in data.list() { for name in data.list() {
store.add(name).unwrap(); match store.add(name) {
Ok(_) => (),
Err(err) => return FromCache::Error(err),
}
} }
FromCache::Ok FromCache::Ok
} }

View File

@ -146,6 +146,24 @@ mod mtt {
let output = mtt1.session().await.unwrap(); let output = mtt1.session().await.unwrap();
assert_eq!(output.list(), [db1, db2]); assert_eq!(output.list(), [db1, db2]);
} }
#[async_std::test]
async fn fail_on_duplicates() {
let dir = tempdir().unwrap();
let mtt1 = start_db(dir.path()).await.unwrap();
let mtt2 = mtt1.clone();
let name = "unique_only";
let mut store1 = mtt1.session().await.unwrap();
let mut store2 = mtt2.session().await.unwrap();
store1.add(name).unwrap();
store2.add(name).unwrap();
mtt1.commit(store1).await.unwrap();
let output = mtt2.commit(store2).await;
match output {
Ok(_) => assert!(false, "Should have returned an error"),
Err(_) => (),
}
}
} }
pub async fn start_db<P>(dir: P) -> Result<MoreThanText, MTTError> pub async fn start_db<P>(dir: P) -> Result<MoreThanText, MTTError>