Removed databases with empty names.
This commit is contained in:
parent
6e6de135ef
commit
766d2e753a
@ -14,7 +14,7 @@ impl Databases {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_database(&mut self, name: &str, id: &str) -> Option<String> {
|
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
|
None
|
||||||
} else {
|
} else {
|
||||||
self.db_map.insert(name.to_string(), id.to_string());
|
self.db_map.insert(name.to_string(), id.to_string());
|
||||||
@ -96,6 +96,15 @@ mod functions {
|
|||||||
assert_eq!(output, Some(id.to_string()));
|
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]
|
#[test]
|
||||||
fn entry_cannot_be_over_written() {
|
fn entry_cannot_be_over_written() {
|
||||||
let name = "barney";
|
let name = "barney";
|
||||||
|
Loading…
Reference in New Issue
Block a user