test: Add Dn type tests
This commit is contained in:
parent
cfa4b8a437
commit
68fddc2de2
1 changed files with 38 additions and 0 deletions
38
src/dn.rs
38
src/dn.rs
|
|
@ -24,6 +24,10 @@ impl Dn {
|
|||
pub fn from_dn_str(input: &str) -> Result<Self, LdapError> {
|
||||
let mut keys: IndexMap<String, Vec<String>> = IndexMap::new();
|
||||
|
||||
if input == "" {
|
||||
return Ok(Self { keys });
|
||||
}
|
||||
|
||||
for query in input.split(',') {
|
||||
let mut query_parts = query.split('=');
|
||||
// Here we have key=val pairs
|
||||
|
|
@ -98,3 +102,37 @@ impl Dn {
|
|||
self.keys.insert("dc".to_string(), domain_components);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_basic_dn_str() {
|
||||
let s = "cn=admin,ou=people,dc=example,dc=com";
|
||||
let mut dn = Dn::from_dn_str(s).unwrap();
|
||||
|
||||
assert_eq!(&dn.to_dn_string(), s);
|
||||
assert_eq!(dn.get_hostname().as_deref(), Some("example.com"));
|
||||
dn.set_hostname("a.localhost", false);
|
||||
assert_eq!(dn.get_hostname().as_deref(), Some("a.localhost"));
|
||||
assert_eq!(&dn.to_dn_string(), "cn=admin,ou=people,dc=a,dc=localhost");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_dn_str() {
|
||||
let s = "";
|
||||
let mut dn = Dn::from_dn_str(s).unwrap();
|
||||
|
||||
assert_eq!(&dn.to_dn_string(), s);
|
||||
assert!(dn.get_hostname().is_none());
|
||||
|
||||
dn.set_hostname("a.localhost", false);
|
||||
assert_eq!(dn.get_hostname().as_deref(), None);
|
||||
assert_eq!(&dn.to_dn_string(), s);
|
||||
|
||||
dn.set_hostname("a.localhost", true);
|
||||
assert_eq!(dn.get_hostname().as_deref(), Some("a.localhost"));
|
||||
assert_eq!(&dn.to_dn_string(), "dc=a,dc=localhost");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue