Skip to content

Commit

Permalink
test from and to bytes in rdata for srv rdata.
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Jul 17, 2024
1 parent b9ad8bd commit 7cbc0ad
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/message/rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ mod resolver_query_tests {
use super::nsec3param_rdata::Nsec3ParamRdata;
use super::tsig_rdata::TSigRdata;
use super::aaaa_rdata::AAAARdata;
use super::srv_rdata::SrvRdata;
use std::net::IpAddr;
use std::vec;

Expand Down Expand Up @@ -760,6 +761,17 @@ mod resolver_query_tests {
assert_eq!(bytes, expected_bytes);
}

#[test]
fn to_bytes_srv_rdata(){
let srv_rdata = SrvRdata::new_with_values(1, 2, 3, DomainName::new_from_str("example.com"));

let expected_bytes = [0, 1, 0, 2, 0, 3, 7, 101, 120, 97, 109, 112, 108, 101, 3, 99, 111, 109, 0];

let bytes = Rdata::SRV(srv_rdata).to_bytes();

assert_eq!(bytes, expected_bytes);
}

//from bytes tests
#[test]
fn from_bytes_a_ch_rdata(){
Expand Down Expand Up @@ -1108,6 +1120,21 @@ mod resolver_query_tests {
}
}

#[test]
fn from_bytes_srv_rdata(){
let data_bytes = [0, 1, 0, 2, 0, 3, 7, 101, 120, 97, 109, 112, 108, 101, 3, 99, 111, 109, 0, 0, 33, 0, 1];
let rdata = Rdata::from_bytes(&data_bytes, &data_bytes).unwrap();
match rdata {
Rdata::SRV(val) => {
assert_eq!(val.get_priority(), 1);
assert_eq!(val.get_weight(), 2);
assert_eq!(val.get_port(), 3);
assert_eq!(val.get_target().get_name(), "example.com");
}
_ => {}
}
}

#[test]
#[should_panic]
fn from_bytes_format_error(){
Expand Down

0 comments on commit 7cbc0ad

Please sign in to comment.