Run tests on Github Actions
This commit is contained in:
parent
1907b11545
commit
17af030893
6 changed files with 38 additions and 44 deletions
15
.github/workflows/build-rust.yml
vendored
15
.github/workflows/build-rust.yml
vendored
|
|
@ -17,21 +17,24 @@ jobs:
|
||||||
platform: Linux
|
platform: Linux
|
||||||
packages:
|
packages:
|
||||||
- gcc-aarch64-linux-gnu
|
- gcc-aarch64-linux-gnu
|
||||||
targets:
|
test-targets:
|
||||||
- x86_64-unknown-linux-gnu
|
- x86_64-unknown-linux-gnu
|
||||||
|
targets:
|
||||||
- aarch64-unknown-linux-gnu
|
- aarch64-unknown-linux-gnu
|
||||||
- os: macos-12
|
- os: macos-12
|
||||||
platform: macOS
|
platform: macOS
|
||||||
targets:
|
test-targets:
|
||||||
- x86_64-apple-darwin
|
- x86_64-apple-darwin
|
||||||
|
targets:
|
||||||
- aarch64-apple-darwin
|
- aarch64-apple-darwin
|
||||||
- aarch64-apple-ios
|
- aarch64-apple-ios
|
||||||
- aarch64-apple-ios-sim
|
- aarch64-apple-ios-sim
|
||||||
- x86_64-apple-ios
|
- x86_64-apple-ios
|
||||||
- os: windows-2022
|
- os: windows-2022
|
||||||
platform: Windows
|
platform: Windows
|
||||||
targets:
|
test-targets:
|
||||||
- x86_64-pc-windows-msvc
|
- x86_64-pc-windows-msvc
|
||||||
|
targets:
|
||||||
- aarch64-pc-windows-msvc
|
- aarch64-pc-windows-msvc
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
env:
|
env:
|
||||||
|
|
@ -59,7 +62,7 @@ jobs:
|
||||||
targets: ${{ join(matrix.targets, ', ') }}
|
targets: ${{ join(matrix.targets, ', ') }}
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cargo build --verbose --workspace --all-features --target ${{ join(matrix.targets, ' --target ') }}
|
run: cargo build --verbose --workspace --all-features --target ${{ join(matrix.targets, ' --target ') }} --target ${{ join(matrix.test-targets, ' --target ') }}
|
||||||
- name: Post-Build Tests
|
- name: Test
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cargo test
|
run: cargo test --verbose --workspace --all-features --target ${{ join(matrix.test-targets, ' --target ') }}
|
||||||
|
|
|
||||||
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
|
|
@ -8,15 +8,6 @@
|
||||||
"editor.acceptSuggestionOnEnter": "on",
|
"editor.acceptSuggestionOnEnter": "on",
|
||||||
"rust-analyzer.restartServerOnConfigChange": true,
|
"rust-analyzer.restartServerOnConfigChange": true,
|
||||||
"rust-analyzer.cargo.features": "all",
|
"rust-analyzer.cargo.features": "all",
|
||||||
"rust-analyzer.check.overrideCommand": [
|
|
||||||
"cargo",
|
|
||||||
"clippy",
|
|
||||||
"--fix",
|
|
||||||
"--workspace",
|
|
||||||
"--message-format=json",
|
|
||||||
"--all-targets",
|
|
||||||
"--allow-dirty"
|
|
||||||
],
|
|
||||||
"[rust]": {
|
"[rust]": {
|
||||||
"editor.defaultFormatter": "rust-lang.rust-analyzer",
|
"editor.defaultFormatter": "rust-lang.rust-analyzer",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use fehler::throws;
|
use fehler::throws;
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use std::net::{Ipv4Addr};
|
use std::net::Ipv4Addr;
|
||||||
use tun::TunInterface;
|
use tun::TunInterface;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -26,6 +26,8 @@ fn test_set_get_ipv4() {
|
||||||
#[throws]
|
#[throws]
|
||||||
#[cfg(not(any(target_os = "windows", target_vendor = "apple")))]
|
#[cfg(not(any(target_os = "windows", target_vendor = "apple")))]
|
||||||
fn test_set_get_ipv6() {
|
fn test_set_get_ipv6() {
|
||||||
|
use std::net::Ipv6Addr;
|
||||||
|
|
||||||
let tun = TunInterface::new()?;
|
let tun = TunInterface::new()?;
|
||||||
|
|
||||||
let addr = Ipv6Addr::new(1, 1, 1, 1, 1, 1, 1, 1);
|
let addr = Ipv6Addr::new(1, 1, 1, 1, 1, 1, 1, 1);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use fehler::throws;
|
use fehler::throws;
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use std::io::Write;
|
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use tun::TunInterface;
|
use tun::TunInterface;
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ fn tst_read() {
|
||||||
println!("tun ip: {:?}", tun.ipv4_addr()?);
|
println!("tun ip: {:?}", tun.ipv4_addr()?);
|
||||||
println!("Waiting for a packet...");
|
println!("Waiting for a packet...");
|
||||||
let buf = &mut [0u8; 1500];
|
let buf = &mut [0u8; 1500];
|
||||||
let res = tun.read(buf);
|
let res = tun.recv(buf);
|
||||||
println!("Received!");
|
println!("Received!");
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
}
|
}
|
||||||
|
|
@ -28,9 +28,9 @@ fn tst_read() {
|
||||||
#[ignore = "requires interactivity"]
|
#[ignore = "requires interactivity"]
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn write_packets() {
|
fn write_packets() {
|
||||||
let mut tun = TunInterface::new()?;
|
let tun = TunInterface::new()?;
|
||||||
let mut buf = [0u8; 1500];
|
let mut buf = [0u8; 1500];
|
||||||
buf[0] = 6 << 4;
|
buf[0] = 6 << 4;
|
||||||
let bytes_written = tun.write(&buf)?;
|
let bytes_written = tun.send(&buf)?;
|
||||||
assert_eq!(bytes_written, 1504);
|
assert_eq!(bytes_written, 1504);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
tun/tests/tokio.rs
Normal file
22
tun/tests/tokio.rs
Normal 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);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue