sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
#[cfg(feature = "network")]
use std::str::FromStr;

#[cfg(feature = "network")]
use sinf::network::{IpNetwork, MacAddr};

#[cfg(feature = "network")]
#[test]
fn mac_address_rejects_invalid_input() {
    for input in [
        "",
        "0",
        "zz:zz:zz:zz:zz:zz",
        "1:2:3:4:5:6",
        "12:34:56:78:9a",
        "12:34:56:78:9a:bc:de",
        "12-34-56-78-9a-bc",
        ":::::",
    ] {
        assert!(MacAddr::from_str(input).is_err(), "{input:?} must fail");
    }
}

#[cfg(feature = "network")]
#[test]
fn ip_network_rejects_invalid_input() {
    for input in [
        "",
        "/",
        "1.2.3.4",
        "999.1.1.1/24",
        "::1",
        "::1/129",
        "1.2.3.4/33",
        "hello/24",
    ] {
        assert!(IpNetwork::from_str(input).is_err(), "{input:?} must fail");
    }
    assert!(IpNetwork::from_str("1.2.3.4/32").is_ok());
    assert!(IpNetwork::from_str("::1/128").is_ok());
}

#[cfg(all(feature = "network", feature = "serde"))]
#[test]
fn serde_rejects_invalid_ip_prefix() {
    let input = r#"{"addr":"127.0.0.1","prefix":64}"#;
    assert!(serde_json::from_str::<IpNetwork>(input).is_err());
}

#[cfg(feature = "system")]
#[test]
fn system_creation_does_not_panic() {
    let _ = sinf::system::System::new();
}

#[cfg(feature = "hardware")]
#[test]
fn hardware_inventory_does_not_panic() {
    let _ = sinf::hardware::Hardware::new();
}