Skip tun tokio test without tun access
This commit is contained in:
parent
8957af0e05
commit
fc79766a31
1 changed files with 22 additions and 3 deletions
|
|
@ -1,10 +1,27 @@
|
||||||
#[cfg(all(feature = "tokio", not(target_os = "windows")))]
|
#[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<tun::TunInterface> {
|
||||||
|
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]
|
#[tokio::test]
|
||||||
#[cfg(all(feature = "tokio", not(target_os = "windows")))]
|
#[cfg(all(feature = "tokio", not(target_os = "windows")))]
|
||||||
async fn test_create() {
|
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();
|
let _ = tun::tokio::TunInterface::new(tun).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -12,7 +29,9 @@ async fn test_create() {
|
||||||
#[ignore = "requires interactivity"]
|
#[ignore = "requires interactivity"]
|
||||||
#[cfg(all(feature = "tokio", not(target_os = "windows")))]
|
#[cfg(all(feature = "tokio", not(target_os = "windows")))]
|
||||||
async fn test_write() {
|
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]))
|
tun.set_ipv4_addr(Ipv4Addr::from([192, 168, 1, 10]))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let async_tun = tun::tokio::TunInterface::new(tun).unwrap();
|
let async_tun = tun::tokio::TunInterface::new(tun).unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue