From b65a5b1465d938d0ca86f31f4fdd46e4b0b96b65 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Wed, 17 Jul 2024 13:49:59 -0400 Subject: [PATCH] add basic tests --- src/message/rdata.rs | 1 + src/message/rdata/srv_rdata.rs | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/message/rdata.rs b/src/message/rdata.rs index 4075b0c0..2aa10fe5 100644 --- a/src/message/rdata.rs +++ b/src/message/rdata.rs @@ -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}; diff --git a/src/message/rdata/srv_rdata.rs b/src/message/rdata/srv_rdata.rs index c0ec4c34..2461c000 100644 --- a/src/message/rdata/srv_rdata.rs +++ b/src/message/rdata/srv_rdata.rs @@ -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")); + } } \ No newline at end of file