فهرست منبع

Add test for composing request bytes

Benjamin Sago 4 سال پیش
والد
کامیت
03987b0834
1فایلهای تغییر یافته به همراه36 افزوده شده و 0 حذف شده
  1. 36 0
      dns/src/wire.rs

+ 36 - 0
dns/src/wire.rs

@@ -485,6 +485,42 @@ mod test {
     use std::net::Ipv4Addr;
     use pretty_assertions::assert_eq;
 
+    #[test]
+    fn build_request() {
+        let request = Request {
+            transaction_id: 0xceac,
+            flags: Flags::query(),
+            query: Query {
+                qname: Labels::encode("rfcs.io").unwrap(),
+                qclass: QClass::Other(0x42),
+                qtype: 0x1234,
+            },
+            additional: Some(Request::additional_record()),
+        };
+
+        let result = vec![
+            0xce, 0xac,  // transaction ID
+            0x01, 0x00,  // flags (standard query)
+            0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,  // counts (1, 0, 0, 1)
+
+            // query:
+            0x04, 0x72, 0x66, 0x63, 0x73, 0x02, 0x69, 0x6f, 0x00,  // qname
+            0x12, 0x34,  // type
+            0x00, 0x42,  // class
+
+            // OPT record:
+            0x00,  // name
+            0x00, 0x29,  // type OPT
+            0x02, 0x00,  // UDP payload size
+            0x00,  // higher bits
+            0x00,  // EDNS(0) version
+            0x00, 0x00,  // more flags
+            0x00, 0x00,  // no data
+        ];
+
+        assert_eq!(request.to_bytes().unwrap(), result);
+    }
+
     #[test]
     fn complete_response() {