From fc79766a318b9f356eb73462ef8859e421a25c27 Mon Sep 17 00:00:00 2001 From: Conrad Kramer Date: Thu, 19 Mar 2026 04:56:56 -0700 Subject: [PATCH] Skip tun tokio test without tun access --- tun/tests/tokio.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tun/tests/tokio.rs b/tun/tests/tokio.rs index 097387c..ddec6b3 100644 --- a/tun/tests/tokio.rs +++ b/tun/tests/tokio.rs @@ -1,10 +1,27 @@ #[cfg(all(feature = "tokio", not(target_os = "windows")))] -use std::net::Ipv4Addr; +use std::{ + io::ErrorKind, + net::Ipv4Addr, +}; + +#[cfg(all(feature = "tokio", not(target_os = "windows")))] +fn open_test_tun() -> Option { + match tun::TunInterface::new() { + Ok(tun) => Some(tun), + Err(error) if matches!(error.kind(), ErrorKind::NotFound | ErrorKind::PermissionDenied) => { + eprintln!("skipping test: {}", error); + None + } + Err(error) => panic!("failed to create tun interface: {error}"), + } +} #[tokio::test] #[cfg(all(feature = "tokio", not(target_os = "windows")))] async fn test_create() { - let tun = tun::TunInterface::new().unwrap(); + let Some(tun) = open_test_tun() else { + return; + }; let _ = tun::tokio::TunInterface::new(tun).unwrap(); } @@ -12,7 +29,9 @@ async fn test_create() { #[ignore = "requires interactivity"] #[cfg(all(feature = "tokio", not(target_os = "windows")))] async fn test_write() { - let tun = tun::TunInterface::new().unwrap(); + let Some(tun) = open_test_tun() else { + return; + }; tun.set_ipv4_addr(Ipv4Addr::from([192, 168, 1, 10])) .unwrap(); let async_tun = tun::tokio::TunInterface::new(tun).unwrap();