Move tests into a separate directory
Also run these tests on Github Actions as part of the PR request flow.
This commit is contained in:
parent
a2e93278c1
commit
86b53c9dcd
6 changed files with 68 additions and 95 deletions
|
|
@ -156,32 +156,3 @@ impl TunInterface {
|
|||
.map_err(|_| Error::new(ErrorKind::Other, "Conversion error"))?
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
#[test]
|
||||
fn mtu() {
|
||||
let interf = TunInterface::new().unwrap();
|
||||
|
||||
interf.set_mtu(500).unwrap();
|
||||
|
||||
assert_eq!(interf.mtu().unwrap(), 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[throws]
|
||||
fn netmask() {
|
||||
let interf = TunInterface::new()?;
|
||||
|
||||
let netmask = Ipv4Addr::new(255, 0, 0, 0);
|
||||
let addr = Ipv4Addr::new(192, 168, 1, 1);
|
||||
|
||||
interf.set_ipv4_addr(addr)?;
|
||||
interf.set_netmask(netmask)?;
|
||||
|
||||
assert_eq!(interf.netmask()?, netmask);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,32 +172,3 @@ impl TunInterface {
|
|||
self.socket.send(buf)?
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::TunInterface;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
#[test]
|
||||
fn mtu() {
|
||||
let interf = TunInterface::new().unwrap();
|
||||
|
||||
interf.set_mtu(500).unwrap();
|
||||
|
||||
assert_eq!(interf.mtu().unwrap(), 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[throws]
|
||||
fn netmask() {
|
||||
let interf = TunInterface::new()?;
|
||||
|
||||
let netmask = Ipv4Addr::new(255, 0, 0, 0);
|
||||
let addr = Ipv4Addr::new(192, 168, 1, 1);
|
||||
|
||||
interf.set_ipv4_addr(addr)?;
|
||||
interf.set_netmask(netmask)?;
|
||||
|
||||
assert_eq!(interf.netmask()?, netmask);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,39 +61,4 @@ pub fn string_to_ifname(name: &str) -> [libc::c_char; libc::IFNAMSIZ] {
|
|||
let len = name.len().min(buf.len());
|
||||
buf[..len].copy_from_slice(unsafe { &*(name.as_bytes() as *const _ as *const [libc::c_char]) });
|
||||
buf
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use super::*;
|
||||
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
#[throws]
|
||||
#[test]
|
||||
fn tst_read() {
|
||||
// This test is interactive, you need to send a packet to any server through 192.168.1.10
|
||||
// EG. `sudo route add 8.8.8.8 192.168.1.10`,
|
||||
//`dig @8.8.8.8 hackclub.com`
|
||||
let mut tun = TunInterface::new()?;
|
||||
println!("tun name: {:?}", tun.name()?);
|
||||
tun.set_ipv4_addr(Ipv4Addr::from([192, 168, 1, 10]))?;
|
||||
println!("tun ip: {:?}", tun.ipv4_addr()?);
|
||||
println!("Waiting for a packet...");
|
||||
let buf = &mut [0u8; 1500];
|
||||
let res = tun.recv(buf);
|
||||
println!("Received!");
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[throws]
|
||||
fn write_packets() {
|
||||
let tun = TunInterface::new()?;
|
||||
let mut buf = [0u8; 1500];
|
||||
buf[0] = 6 << 4;
|
||||
let bytes_written = tun.send(&buf)?;
|
||||
assert_eq!(bytes_written, 1504);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue