Skip to content

Commit

Permalink
Add another test around a DNS Name edge case
Browse files Browse the repository at this point in the history
Add a test that confirms that Name.size() returns the same result for
both FQDN and non-FQDN even though this is kind of confusing.
  • Loading branch information
56quarters committed Aug 24, 2024
1 parent 5faf1b9 commit 57cbe5a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mtop-client/src/dns/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Name {
}

pub fn size(&self) -> usize {
(self.labels.iter().map(|l| l.len()).sum::<usize>() + self.labels.len()) + 1
self.labels.iter().map(|l| l.len()).sum::<usize>() + self.labels.len() + 1
}

pub fn is_root(&self) -> bool {
Expand Down Expand Up @@ -454,6 +454,21 @@ mod test {
assert_eq!(13, name.size());
}

#[test]
fn test_name_size_non_root_fqdn() {
let name = Name::from_str("example.com").unwrap();
assert!(!name.is_fqdn());
assert_eq!(13, name.size());

// The purpose of the .size() method is to figure out how many bytes this
// name would be when serialized to binary message format. Only FQDN can be
// serialized so we expect the size to be the same between the non-FQDN and
// FQDN version of this name.
let name = name.to_fqdn();
assert!(name.is_fqdn());
assert_eq!(13, name.size());
}

#[test]
fn test_name_write_network_bytes_root() {
let mut cur = Cursor::new(Vec::new());
Expand Down

0 comments on commit 57cbe5a

Please sign in to comment.