Removed databases with empty names.

This commit is contained in:
Jeff Baskin 2023-01-23 11:05:55 -05:00
parent 6e6de135ef
commit 766d2e753a

View File

@ -14,7 +14,7 @@ impl Databases {
}
fn add_database(&mut self, name: &str, id: &str) -> Option<String> {
if self.db_map.contains_key(name) {
if name.len() == 0 || self.db_map.contains_key(name) {
None
} else {
self.db_map.insert(name.to_string(), id.to_string());
@ -96,6 +96,15 @@ mod functions {
assert_eq!(output, Some(id.to_string()));
}
#[test]
fn add_entry_no_name() {
let name = "";
let id = "123456";
let mut dbs = Databases::new();
let output = dbs.add_database(name, id);
assert_eq!(output, None);
}
#[test]
fn entry_cannot_be_over_written() {
let name = "barney";