Skip to content

Commit

Permalink
add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Jul 17, 2024
1 parent 5dd10dc commit b65a5b1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/message/rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod dnskey_rdata;
pub mod nsec3_rdata;
pub mod nsec3param_rdata;
pub mod tsig_rdata;
pub mod srv_rdata;

use core::fmt;
use crate::message::resource_record::{FromBytes, ToBytes};
Expand Down
37 changes: 37 additions & 0 deletions src/message/rdata/srv_rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,41 @@ impl SrvRdata {
pub fn set_target(&mut self, target: DomainName) {
self.target = target;
}
}

#[cfg(test)]
mod srv_rdata_tests {
use super::*;

#[test]
fn construct_srv_rdata() {
let srv_rdata = SrvRdata::new();
assert_eq!(srv_rdata.get_priority(), 0);
assert_eq!(srv_rdata.get_weight(), 0);
assert_eq!(srv_rdata.get_port(), 0);
assert_eq!(srv_rdata.get_target(), DomainName::new());
}

#[test]
fn construct_srv_rdata_with_values() {
let srv_rdata = SrvRdata::new_with_values(1, 2, 3, DomainName::new_from_str("www.example.com"));
assert_eq!(srv_rdata.get_priority(), 1);
assert_eq!(srv_rdata.get_weight(), 2);
assert_eq!(srv_rdata.get_port(), 3);
assert_eq!(srv_rdata.get_target(), DomainName::new_from_str("www.example.com"));
}

#[test]
fn get_and_set_srv_rdata_values() {
let mut srv_rdata = SrvRdata::new();
srv_rdata.set_priority(1);
srv_rdata.set_weight(2);
srv_rdata.set_port(3);
srv_rdata.set_target(DomainName::new_from_str("www.example.com"));

assert_eq!(srv_rdata.get_priority(), 1);
assert_eq!(srv_rdata.get_weight(), 2);
assert_eq!(srv_rdata.get_port(), 3);
assert_eq!(srv_rdata.get_target(), DomainName::new_from_str("www.example.com"));
}
}

0 comments on commit b65a5b1

Please sign in to comment.