44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
//! Unit tests for server-kind classification.
|
|
|
|
use super::*;
|
|
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
|
|
|
|
#[test]
|
|
fn loopback_addresses_classify_as_local() {
|
|
let v4 = SocketAddr::from((Ipv4Addr::LOCALHOST, 25565));
|
|
let v6 = SocketAddr::from((Ipv6Addr::LOCALHOST, 25565));
|
|
|
|
assert_eq!(
|
|
ServerKind::dedicated(v4),
|
|
ServerKind::Dedicated { remote: false }
|
|
);
|
|
assert_eq!(
|
|
ServerKind::dedicated(v6),
|
|
ServerKind::Dedicated { remote: false }
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn non_loopback_addresses_classify_as_remote() {
|
|
let addr = SocketAddr::from((Ipv4Addr::new(10, 0, 0, 4), 25565));
|
|
assert_eq!(
|
|
ServerKind::dedicated(addr),
|
|
ServerKind::Dedicated { remote: true }
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn each_kind_has_a_distinct_label() {
|
|
assert_eq!(ServerKind::Integrated.label(), "integrated");
|
|
assert_eq!(
|
|
ServerKind::Dedicated { remote: false }.label(),
|
|
"dedicated (local)"
|
|
);
|
|
assert_eq!(
|
|
ServerKind::Dedicated { remote: true }.label(),
|
|
"dedicated (remote)"
|
|
);
|
|
}
|