use std::io;
use varta_client::{classify_send_error, BeatOutcome};
#[cfg(target_os = "linux")]
const ENOBUFS_FOR_THIS_OS: i32 = 105;
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "dragonfly",
))]
const ENOBUFS_FOR_THIS_OS: i32 = 55;
#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "dragonfly",
))]
#[test]
fn enobufs_classifies_as_dropped() {
let err = io::Error::from_raw_os_error(ENOBUFS_FOR_THIS_OS);
assert!(
matches!(classify_send_error(&err), BeatOutcome::Dropped),
"ENOBUFS (code {ENOBUFS_FOR_THIS_OS}) should classify as Dropped"
);
}
#[test]
fn wouldblock_classifies_as_dropped() {
let err = io::Error::from(io::ErrorKind::WouldBlock);
assert!(matches!(classify_send_error(&err), BeatOutcome::Dropped));
}
#[test]
fn connection_refused_classifies_as_dropped() {
let err = io::Error::from(io::ErrorKind::ConnectionRefused);
assert!(matches!(classify_send_error(&err), BeatOutcome::Dropped));
}
#[test]
fn permission_denied_classifies_as_failed() {
let err = io::Error::from_raw_os_error(1);
assert!(
matches!(classify_send_error(&err), BeatOutcome::Failed(_)),
"EPERM should classify as Failed, not Dropped"
);
}