Run tests on Github Actions

This commit is contained in:
Conrad Kramer 2023-08-05 08:32:54 -07:00
parent 1907b11545
commit 17af030893
6 changed files with 38 additions and 44 deletions

View file

@ -32,27 +32,3 @@ impl TunInterface {
}
}
}
#[cfg(test)]
mod tests {
use std::net::Ipv4Addr;
use super::*;
#[tokio::test]
async fn test_create() {
let tun = crate::TunInterface::new().unwrap();
let _async_tun = TunInterface::new(tun).unwrap();
}
#[tokio::test]
async fn test_write() {
let tun = crate::TunInterface::new().unwrap();
tun.set_ipv4_addr(Ipv4Addr::from([192, 168, 1, 10]))
.unwrap();
let async_tun = TunInterface::new(tun).unwrap();
let mut buf = [0u8; 1500];
buf[0] = 6 << 4;
let bytes_written = async_tun.write(&buf).await.unwrap();
assert!(bytes_written > 0);
}
}

View file

@ -1,6 +1,6 @@
use fehler::throws;
use std::io::Error;
use std::net::{Ipv4Addr};
use std::net::Ipv4Addr;
use tun::TunInterface;
#[test]
@ -26,6 +26,8 @@ fn test_set_get_ipv4() {
#[throws]
#[cfg(not(any(target_os = "windows", target_vendor = "apple")))]
fn test_set_get_ipv6() {
use std::net::Ipv6Addr;
let tun = TunInterface::new()?;
let addr = Ipv6Addr::new(1, 1, 1, 1, 1, 1, 1, 1);

View file

@ -1,6 +1,6 @@
use fehler::throws;
use std::io::Error;
use std::io::Write;
use std::net::Ipv4Addr;
use tun::TunInterface;
@ -18,7 +18,7 @@ fn tst_read() {
println!("tun ip: {:?}", tun.ipv4_addr()?);
println!("Waiting for a packet...");
let buf = &mut [0u8; 1500];
let res = tun.read(buf);
let res = tun.recv(buf);
println!("Received!");
assert!(res.is_ok());
}
@ -28,9 +28,9 @@ fn tst_read() {
#[ignore = "requires interactivity"]
#[cfg(not(target_os = "windows"))]
fn write_packets() {
let mut tun = TunInterface::new()?;
let tun = TunInterface::new()?;
let mut buf = [0u8; 1500];
buf[0] = 6 << 4;
let bytes_written = tun.write(&buf)?;
let bytes_written = tun.send(&buf)?;
assert_eq!(bytes_written, 1504);
}

22
tun/tests/tokio.rs Normal file
View file

@ -0,0 +1,22 @@
use std::net::Ipv4Addr;
#[tokio::test]
#[cfg(feature = "tokio")]
async fn test_create() {
let tun = tun::TunInterface::new().unwrap();
let async_tun = tun::tokio::TunInterface::new(tun).unwrap();
}
#[tokio::test]
#[ignore = "requires interactivity"]
#[cfg(all(feature = "tokio", not(target_os = "windows")))]
async fn test_write() {
let tun = tun::TunInterface::new().unwrap();
tun.set_ipv4_addr(Ipv4Addr::from([192, 168, 1, 10]))
.unwrap();
let async_tun = tun::tokio::TunInterface::new(tun).unwrap();
let mut buf = [0u8; 1500];
buf[0] = 6 << 4;
let bytes_written = async_tun.write(&buf).await.unwrap();
assert!(bytes_written > 0);
}