Răsfoiți Sursa

tests: Update to expect presence of UDP local address

chrysn 1 an în urmă
părinte
comite
560a2285de

+ 4 - 1
src/iface/interface/tests/ipv4.rs

@@ -938,7 +938,10 @@ fn test_raw_socket_with_udp_socket(#[case] medium: Medium) {
         socket.recv(),
         Ok((
             &UDP_PAYLOAD[..],
-            IpEndpoint::new(src_addr.into(), 67).into()
+            udp::UdpMetadata {
+                local_address: Some(dst_addr.into()),
+                ..IpEndpoint::new(src_addr.into(), 67).into()
+            }
         ))
     );
 }

+ 8 - 1
src/iface/interface/tests/mod.rs

@@ -109,6 +109,7 @@ fn test_handle_udp_broadcast(
         payload_len: udp_repr.header_len() + UDP_PAYLOAD.len(),
         hop_limit: 0x40,
     });
+    let dst_addr = ip_repr.dst_addr();
 
     // Bind the socket to port 68
     let socket = sockets.get_mut::<udp::Socket>(socket_handle);
@@ -143,7 +144,13 @@ fn test_handle_udp_broadcast(
     assert!(socket.can_recv());
     assert_eq!(
         socket.recv(),
-        Ok((&UDP_PAYLOAD[..], IpEndpoint::new(src_ip.into(), 67).into()))
+        Ok((
+            &UDP_PAYLOAD[..],
+            udp::UdpMetadata {
+                local_address: Some(dst_addr),
+                ..IpEndpoint::new(src_ip.into(), 67).into()
+            }
+        ))
     );
 }
 

+ 16 - 7
src/iface/interface/tests/sixlowpan.rs

@@ -368,14 +368,23 @@ In at rhoncus tortor. Cras blandit tellus diam, varius vestibulum nibh commodo n
         socket.recv(),
         Ok((
             &udp_data[..],
-            IpEndpoint {
-                addr: IpAddress::Ipv6(Ipv6Address([
-                    0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x42, 0x42, 0x42, 0x42, 0x42,
-                    0xb, 0x1a,
-                ])),
-                port: 54217,
+            udp::UdpMetadata {
+                local_address: Some(
+                    Ipv6Address([
+                        0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x92, 0xfc, 0x48, 0xc2, 0xa4,
+                        0x41, 0xfc, 0x76,
+                    ])
+                    .into()
+                ),
+                ..IpEndpoint {
+                    addr: IpAddress::Ipv6(Ipv6Address([
+                        0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x42, 0x42, 0x42, 0x42,
+                        0x42, 0xb, 0x1a,
+                    ])),
+                    port: 54217,
+                }
+                .into()
             }
-            .into()
         ))
     );
 

+ 20 - 4
src/socket/udp.rs

@@ -647,6 +647,13 @@ mod test {
         addr: REMOTE_ADDR.into_address(),
         port: REMOTE_PORT,
     };
+    fn remote_metadata_with_local() -> UdpMetadata {
+        // Would be great as a const once we have const `.into()`.
+        UdpMetadata {
+            local_address: Some(LOCAL_ADDR.into()),
+            ..REMOTE_END.into()
+        }
+    }
 
     pub const LOCAL_IP_REPR: IpRepr = IpReprIpvX(IpvXRepr {
         src_addr: LOCAL_ADDR,
@@ -823,7 +830,10 @@ mod test {
             PAYLOAD,
         );
 
-        assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END.into())));
+        assert_eq!(
+            socket.recv(),
+            Ok((&b"abcdef"[..], remote_metadata_with_local()))
+        );
         assert!(!socket.can_recv());
     }
 
@@ -851,8 +861,14 @@ mod test {
             &REMOTE_UDP_REPR,
             PAYLOAD,
         );
-        assert_eq!(socket.peek(), Ok((&b"abcdef"[..], &REMOTE_END.into(),)));
-        assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END.into(),)));
+        assert_eq!(
+            socket.peek(),
+            Ok((&b"abcdef"[..], &remote_metadata_with_local(),))
+        );
+        assert_eq!(
+            socket.recv(),
+            Ok((&b"abcdef"[..], remote_metadata_with_local(),))
+        );
         assert_eq!(socket.peek(), Err(RecvError::Exhausted));
     }
 
@@ -1025,7 +1041,7 @@ mod test {
             dst_port: LOCAL_PORT,
         };
         socket.process(cx, PacketMeta::default(), &REMOTE_IP_REPR, &repr, &[]);
-        assert_eq!(socket.recv(), Ok((&[][..], REMOTE_END.into())));
+        assert_eq!(socket.recv(), Ok((&[][..], remote_metadata_with_local())));
     }
 
     #[test]