Skip to content

Commit

Permalink
Add happy path tests for alsoKnownAs and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Diane Huxley committed Jun 3, 2024
1 parent 3405197 commit 0ba32fa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/dids/src/methods/dht/document_packet/also_known_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,35 @@ impl AlsoKnownAs {
Ok(also_known_as)
}
}

#[cfg(test)]
mod test {
use crate::methods::dht::document_packet::controller::Controller;

use super::*;

#[test]
fn test_to_and_from_resource_record() {
let also_known_as = vec!["Dave".to_string(), "Bartholemoop".to_string()];
let record = AlsoKnownAs::to_resource_record(&also_known_as)
.expect("expected to convert to DNS record");
let also_known_as2 = AlsoKnownAs::from_resource_record(&record)
.expect("Expected to convert from DNS record");
assert_eq!(also_known_as, also_known_as2);


}

#[test]
fn test_is_aka_record() {
let also_known_as = vec!["Dave".to_string(), "Bartholemoop".to_string()];
let record = AlsoKnownAs::to_resource_record(&also_known_as)
.expect("expected to convert to DNS record");

assert!(AlsoKnownAs::is_aka_record(&record));

let controllers = vec!["Jerb".to_string(), "Carrie Bradshaw".to_string()];
let record = Controller::to_resource_record(&controllers).unwrap();
assert!(!AlsoKnownAs::is_aka_record(&record));
}
}
15 changes: 15 additions & 0 deletions crates/dids/src/methods/dht/document_packet/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ impl Controller {

#[cfg(test)]
mod tests {
use crate::methods::dht::document_packet::also_known_as::AlsoKnownAs;

use super::*;

#[test]
Expand All @@ -62,4 +64,17 @@ mod tests {
.expect("Expected to get a list of strings from resource record");
assert_eq!(controllers, controllers2);
}

#[test]
fn test_is_cnt_record() {
let also_known_as = vec!["Dave".to_string(), "Bartholemoop".to_string()];
let record = Controller::to_resource_record(&also_known_as)
.expect("expected to convert to DNS record");

assert!(Controller::is_cnt_record(&record));

let controllers = vec!["Jerb".to_string(), "Carrie Bradshaw".to_string()];
let record = AlsoKnownAs::to_resource_record(&controllers).unwrap();
assert!(!Controller::is_cnt_record(&record));
}
}

0 comments on commit 0ba32fa

Please sign in to comment.