Compare commits
No commits in common. "e49d6f5e46e40adfc98bc2ae2b6663746cd1bf5d" and "4dad6f7a050a1fd8c6ebd338cbf574ee53d2eee8" have entirely different histories.
e49d6f5e46
...
4dad6f7a05
@ -132,10 +132,10 @@ impl Cache {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
for name in data.list() {
|
for name in data.list() {
|
||||||
let id = self.ids.next().unwrap();
|
match store.add(name) {
|
||||||
match store.add_by_id(name, &id) {
|
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.data.insert(id, FromCache::DB(Database::new()));
|
self.data
|
||||||
|
.insert(self.ids.next().unwrap(), FromCache::DB(Database::new()));
|
||||||
}
|
}
|
||||||
Err(err) => return FromCache::Error(err),
|
Err(err) => return FromCache::Error(err),
|
||||||
}
|
}
|
||||||
@ -228,21 +228,7 @@ mod engine {
|
|||||||
db_out, cache.data
|
db_out, cache.data
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
let store_out = cache.get(ENTRY);
|
// Add test that only ids are in the cache.
|
||||||
match store_out {
|
|
||||||
FromCache::Str(updated_store) => match updated_store.get(name) {
|
|
||||||
Some(output) => {
|
|
||||||
assert_eq!(output.id, Some(id.to_string()));
|
|
||||||
assert!(output.data.is_none(), "Should have removed the database.");
|
|
||||||
}
|
|
||||||
None => assert!(true, "Store should have stored the database."),
|
|
||||||
},
|
|
||||||
_ => assert!(
|
|
||||||
false,
|
|
||||||
"{:?} is not FromCache::Str -- cache is {:?}",
|
|
||||||
db_out, cache.data
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,10 +162,7 @@ mod mtt {
|
|||||||
let output = mtt2.commit(store2).await;
|
let output = mtt2.commit(store2).await;
|
||||||
match output {
|
match output {
|
||||||
Ok(_) => assert!(false, "Should have returned an error"),
|
Ok(_) => assert!(false, "Should have returned an error"),
|
||||||
Err(err) => match err.code {
|
Err(_) => (),
|
||||||
ErrorCode::DuplicateDatabase(_) => (),
|
|
||||||
_ => assert!(false, "{:?} is not ErrorCode::DuplicateDatabase", err.code),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,21 +27,6 @@ impl Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_by_id<S, D>(&mut self, name: S, id: D) -> Result<(), MTTError>
|
|
||||||
where
|
|
||||||
S: Into<String>,
|
|
||||||
D: Into<String>,
|
|
||||||
{
|
|
||||||
let db_name = name.into();
|
|
||||||
match self.get(&db_name) {
|
|
||||||
Some(_) => Err(MTTError::from_code(ErrorCode::DuplicateDatabase(db_name))),
|
|
||||||
None => {
|
|
||||||
self.data.insert(db_name, Data::from_id(id.into()));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(&self, name: &str) -> Option<&Data<Database>> {
|
pub fn get(&self, name: &str) -> Option<&Data<Database>> {
|
||||||
self.data.get(name)
|
self.data.get(name)
|
||||||
}
|
}
|
||||||
@ -102,53 +87,6 @@ mod storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn add_using_cache_id() {
|
|
||||||
let mut store = Store::new();
|
|
||||||
let name = "fred";
|
|
||||||
let id = "12345";
|
|
||||||
store.add_by_id(name, id).unwrap();
|
|
||||||
let output = store.get(name).unwrap();
|
|
||||||
assert!(output.data.is_none(), "there should be no data");
|
|
||||||
assert_eq!(output.id, Some(id.to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn add_by_cache_id_name_string() {
|
|
||||||
let mut store = Store::new();
|
|
||||||
let name = "barney";
|
|
||||||
let id = "67890";
|
|
||||||
store.add_by_id(name.to_string(), id).unwrap();
|
|
||||||
let output = store.get(name).unwrap();
|
|
||||||
assert!(output.data.is_none(), "there should be no data");
|
|
||||||
assert_eq!(output.id, Some(id.to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_duplicate_databases_for_add_by_id() {
|
|
||||||
let mut store = Store::new();
|
|
||||||
let name = "betty";
|
|
||||||
store.add_by_id(name, "fghij").unwrap();
|
|
||||||
match store.add_by_id(name, "klmno") {
|
|
||||||
Ok(_) => assert!(false, "Duplicates should error."),
|
|
||||||
Err(err) => match err.code {
|
|
||||||
ErrorCode::DuplicateDatabase(db_name) => assert_eq!(db_name, name),
|
|
||||||
_ => assert!(false, "{:?} is not DuplicateDatabase", err),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn add_by_cache_id_string() {
|
|
||||||
let mut store = Store::new();
|
|
||||||
let name = "wilma";
|
|
||||||
let id = "abcdef";
|
|
||||||
store.add_by_id(name, id.to_string()).unwrap();
|
|
||||||
let output = store.get(name).unwrap();
|
|
||||||
assert!(output.data.is_none(), "there should be no data");
|
|
||||||
assert_eq!(output.id, Some(id.to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_bad_database() -> Result<(), MTTError> {
|
fn get_bad_database() -> Result<(), MTTError> {
|
||||||
let store = Store::new();
|
let store = Store::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user