Skip to content

Commit

Permalink
Add test for enodev errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gluxon committed Sep 11, 2022
1 parent 4692519 commit 33d2db3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/enodev.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#[cfg(target_os = "linux")]
use wireguard_uapi::set;
#[cfg(target_os = "linux")]
use wireguard_uapi::WgSocket;

#[cfg(target_os = "linux")]
#[test]
// WireGuard returns an ENODEV (no device error) when you attempt to update a
// WireGuard device that hasn't been created yet.
//
// Instead of properly reporting this error, the library currently swallows it
// and reports "No ack received". Adding this test now to record what currently
// happens and comment on the ideal future state.
//
// See https://github.com/gluxon/wireguard-uapi-rs/issues/28
fn missing_device_returns_sensible_error() -> anyhow::Result<()> {
let mut wg = WgSocket::connect()?;
let ifname = "wg404";

let set_device_args = set::Device::from_ifname(ifname)
.flags(vec![set::WgDeviceF::ReplacePeers])
.peers(vec![]);
let set_device_result = wg.set_device(set_device_args);

let existing_err_message = set_device_result.unwrap_err().to_string();

// TODO: Ensure this library returns more sensible errors. Update the "No
// ack received" string below to "No device found by interface name or
// public key".
assert_eq!(existing_err_message, "No ack received");

Ok(())
}

0 comments on commit 33d2db3

Please sign in to comment.