ufwctl 0.1.0

Linux-only Rust library for managing UFW firewall rules
Documentation
/// Tests for port-related public API: PortRule.
use ufwctl::{PortRule, Protocol, RuleStatus};

#[test]
fn port_rule_fields() {
    let rule = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    assert_eq!(rule.port, 22);
    assert_eq!(rule.protocol, Protocol::Tcp);
    assert_eq!(rule.status, RuleStatus::Allowed);
}

#[test]
fn port_rule_equality() {
    let a = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    let b = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    assert_eq!(a, b);
}

#[test]
fn port_rule_inequality_port() {
    let a = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    let b = PortRule {
        port: 80,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    assert_ne!(a, b);
}

#[test]
fn port_rule_inequality_protocol() {
    let a = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    let b = PortRule {
        port: 22,
        protocol: Protocol::Udp,
        status: RuleStatus::Allowed,
    };
    assert_ne!(a, b);
}

#[test]
fn port_rule_inequality_status() {
    let a = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    let b = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Denied,
    };
    assert_ne!(a, b);
}

#[test]
fn port_rule_debug() {
    let rule = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    let s = format!("{rule:?}");
    assert!(s.contains("22"));
}

#[test]
fn port_rule_clone() {
    let a = PortRule {
        port: 22,
        protocol: Protocol::Tcp,
        status: RuleStatus::Allowed,
    };
    let b = a.clone();
    assert_eq!(a, b);
}