pub struct RemotingHelper;
impl RemotingHelper {
pub fn parse_host_from_address(address: Option<&str>) -> String {
match address {
Some(addr) if !addr.is_empty() => addr.split(':').next().unwrap_or_default().to_string(),
_ => String::new(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_host_from_valid_address() {
let result = RemotingHelper::parse_host_from_address(Some("127.0.0.1:8080"));
assert_eq!(result, "127.0.0.1");
}
#[test]
fn parse_host_from_address_without_port() {
let result = RemotingHelper::parse_host_from_address(Some("localhost"));
assert_eq!(result, "localhost");
}
#[test]
fn parse_host_from_empty_address() {
let result = RemotingHelper::parse_host_from_address(Some(""));
assert_eq!(result, "");
}
#[test]
fn parse_host_from_none_address() {
let result = RemotingHelper::parse_host_from_address(None);
assert_eq!(result, "");
}
}