Skip to content

Commit

Permalink
Add tests for NsecRdata to_bytes function
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Jan 4, 2024
1 parent 6b36b61 commit b509787
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/message/rdata/nsec_rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,26 @@ mod nsec_rdata_test{

assert_eq!(nsec_rdata.get_type_bit_maps(), vec![Rtype::A, Rtype::NS]);
}

#[test]
fn to_bytes_test() {
let mut nsec_rdata = NsecRdata::new(DomainName::new(), vec![]);

let mut domain_name = DomainName::new();
domain_name.set_name(String::from("host.example.com"));
nsec_rdata.set_next_domain_name(domain_name);

nsec_rdata.set_type_bit_maps(vec![Rtype::A, Rtype::MX, Rtype::RRSIG, Rtype::NSEC, Rtype::UNKNOWN(1234)]);

let next_domain_name_bytes = vec![4, 104, 111, 115, 116, 7, 101, 120, 97, 109, 112, 108, 101, 3, 99, 111, 109, 0];

let bit_map_bytes_to_test = vec![0, 6, 64, 1, 0, 0, 0, 3,
4, 27, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32];

let bytes_to_test = [next_domain_name_bytes, bit_map_bytes_to_test].concat();

assert_eq!(nsec_rdata.to_bytes(), bytes_to_test);
}
}

0 comments on commit b509787

Please sign in to comment.