use super::error::NetworkError;
use crate::shared::command::CommandExecutor;
#[derive(Debug)]
pub struct NetstatClient {
command_executor: CommandExecutor,
}
impl Default for NetstatClient {
fn default() -> Self {
Self::new()
}
}
impl NetstatClient {
#[must_use]
pub fn new() -> Self {
Self {
command_executor: CommandExecutor::new(),
}
}
pub fn list_tcp_listening_ports(&self) -> Result<String, NetworkError> {
let args = vec!["-tlnp"];
self.command_executor
.run_command("netstat", &args, None)
.map(|result| result.stdout)
.map_err(NetworkError::NetstatFailed)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_should_create_netstat_client() {
let _client = NetstatClient::new();
}
#[test]
fn it_should_have_default_implementation() {
let _client = NetstatClient::default();
}
}