group tests (#23)

Co-authored-by: Tobias Ottenweller <tobi@ottenweller.net>
Reviewed-on: #23
Co-authored-by: mice_on_drugs <tobi@ottenweller.net>
Co-committed-by: mice_on_drugs <tobi@ottenweller.net>
This commit is contained in:
mice_on_drugs 2022-05-08 17:32:27 +02:00 committed by ddidderr
parent df255f9267
commit a72e40d9cb

View File

@ -229,10 +229,13 @@ pub enum DNSParseError {
#[cfg(test)]
mod tests {
use super::*;
mod from_udp_datagram {
mod header_length {
use super::super::super::*;
#[test]
fn parse_dns_header_too_short() {
fn too_short() {
// minimal header with 1 byte missing
let dns_query = [
0x13, 0x37, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -240,9 +243,13 @@ mod tests {
let parse_result = DNSHeader::from_udp_datagram(&dns_query);
assert_eq!(parse_result.err().unwrap(), DNSParseError::DatagramTooShort);
}
}
mod opcode {
use super::super::super::*;
#[test]
fn parse_dns_header_opcode_invalid() {
fn invalid() {
let mut dns_query = [
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
@ -262,7 +269,7 @@ mod tests {
}
#[test]
fn parse_dns_header_opcode_valid() -> Result<(), DNSParseError> {
fn valid() -> Result<(), DNSParseError> {
let mut dns_query = [
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
@ -285,9 +292,13 @@ mod tests {
}
Ok(())
}
}
mod message_type {
use super::super::super::*;
#[test]
fn parse_dns_header_message_type_query() -> Result<(), DNSParseError> {
fn query() -> Result<(), DNSParseError> {
let dns_query = [
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
@ -297,7 +308,7 @@ mod tests {
}
#[test]
fn parse_dns_header_message_type_response() -> Result<(), DNSParseError> {
fn response() -> Result<(), DNSParseError> {
let dns_query = [
0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
@ -305,9 +316,13 @@ mod tests {
assert_eq!(parse_result?.message_type, DNSMessageType::Response);
Ok(())
}
}
mod response_code {
use super::super::super::*;
#[test]
fn parse_dns_header_response_code_invalid() {
fn invalid() {
let mut dns_query = [
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
@ -329,7 +344,7 @@ mod tests {
}
#[test]
fn parse_dns_header_response_code_valid() -> Result<(), DNSParseError> {
fn valid() -> Result<(), DNSParseError> {
let mut dns_query = [
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
@ -361,3 +376,5 @@ mod tests {
Ok(())
}
}
}
}