diff options
-rw-r--r-- | src/display/components/display_bandwidth.rs | 2 | ||||
-rw-r--r-- | src/display/components/header_details.rs | 18 | ||||
-rw-r--r-- | src/display/components/help_text.rs | 14 | ||||
-rw-r--r-- | src/display/components/layout.rs | 20 | ||||
-rw-r--r-- | src/display/components/table.rs | 31 | ||||
-rw-r--r-- | src/display/raw_terminal_backend.rs | 8 | ||||
-rw-r--r-- | src/display/ui.rs | 23 | ||||
-rw-r--r-- | src/display/ui_state.rs | 12 | ||||
-rw-r--r-- | src/main.rs | 35 | ||||
-rw-r--r-- | src/network/connection.rs | 15 | ||||
-rw-r--r-- | src/network/dns/client.rs | 4 | ||||
-rw-r--r-- | src/network/dns/resolver.rs | 12 | ||||
-rw-r--r-- | src/network/sniffer.rs | 49 | ||||
-rw-r--r-- | src/network/utilization.rs | 4 | ||||
-rw-r--r-- | src/os/linux.rs | 18 | ||||
-rw-r--r-- | src/os/lsof.rs | 9 | ||||
-rw-r--r-- | src/os/lsof_utils.rs | 8 | ||||
-rw-r--r-- | src/os/shared.rs | 21 | ||||
-rw-r--r-- | src/os/windows.rs | 6 | ||||
-rw-r--r-- | src/tests/cases/raw_mode.rs | 27 | ||||
-rw-r--r-- | src/tests/cases/test_utils.rs | 29 | ||||
-rw-r--r-- | src/tests/cases/ui.rs | 35 | ||||
-rw-r--r-- | src/tests/fakes/fake_input.rs | 20 | ||||
-rw-r--r-- | src/tests/fakes/fake_output.rs | 13 |
24 files changed, 231 insertions, 202 deletions
diff --git a/src/display/components/display_bandwidth.rs b/src/display/components/display_bandwidth.rs index ff2dcce..779e419 100644 --- a/src/display/components/display_bandwidth.rs +++ b/src/display/components/display_bandwidth.rs @@ -1,4 +1,4 @@ -use ::std::fmt; +use std::fmt; pub struct DisplayBandwidth { pub bandwidth: f64, diff --git a/src/display/components/header_details.rs b/src/display/components/header_details.rs index 768f64d..937a03b 100644 --- a/src/display/components/header_details.rs +++ b/src/display/components/header_details.rs @@ -1,11 +1,15 @@ +use std::time::{Duration, Instant}; + +use ratatui::{ + backend::Backend, + layout::{Alignment, Rect}, + style::{Color, Modifier, Style}, + terminal::Frame, + text::Span, + widgets::Paragraph, +}; + use crate::display::{DisplayBandwidth, UIState}; -use ::ratatui::backend::Backend; -use ::ratatui::layout::{Alignment, Rect}; -use ::ratatui::style::{Color, Modifier, Style}; -use ::ratatui::terminal::Frame; -use ::ratatui::text::Span; -use ::ratatui::widgets::Paragraph; -use ::std::time::{Duration, Instant}; const SECONDS_IN_DAY: u64 = 86400; diff --git a/src/display/components/help_text.rs b/src/display/components/help_text.rs index 6fd0759..de7aa37 100644 --- a/src/display/components/help_text.rs +++ b/src/display/components/help_text.rs @@ -1,9 +1,11 @@ -use ::ratatui::backend::Backend; -use ::ratatui::layout::{Alignment, Rect}; -use ::ratatui::style::{Modifier, Style}; -use ::ratatui::terminal::Frame; -use ::ratatui::text::Span; -use ::ratatui::widgets::Paragraph; +use ratatui::{ + backend::Backend, + layout::{Alignment, Rect}, + style::{Modifier, Style}, + terminal::Frame, + text::Span, + widgets::Paragraph, +}; pub struct HelpText { pub paused: bool, diff --git a/src/display/components/layout.rs b/src/display/components/layout.rs index 06cc0db..928be3d 100644 --- a/src/display/components/layout.rs +++ b/src/display/components/layout.rs @@ -1,16 +1,16 @@ -use ::ratatui::backend::Backend; -use ::ratatui::layout::{Constraint, Direction, Rect}; -use ::ratatui::terminal::Frame; +use ratatui::{ + backend::Backend, + layout::{Constraint, Direction, Rect}, + terminal::Frame, +}; -use super::HeaderDetails; -use super::HelpText; -use super::Table; +use crate::display::{HeaderDetails, HelpText, Table}; const FIRST_HEIGHT_BREAKPOINT: u16 = 30; const FIRST_WIDTH_BREAKPOINT: u16 = 120; fn top_app_and_bottom_split(rect: Rect) -> (Rect, Rect, Rect) { - let parts = ::ratatui::layout::Layout::default() + let parts = ratatui::layout::Layout::default() .direction(Direction::Vertical) .margin(0) .constraints( @@ -37,7 +37,7 @@ impl<'a> Layout<'a> { .into_iter() .fold(vec![rect], |mut layout, direction| { let last_rect = layout.pop().unwrap(); - let halves = ::ratatui::layout::Layout::default() + let halves = ratatui::layout::Layout::default() .direction(direction) .margin(0) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) @@ -74,12 +74,12 @@ impl<'a> Layout<'a> { self.progressive_split(rect, vec![Direction::Vertical]) } else { // default layout - let halves = ::ratatui::layout::Layout::default() + let halves = ratatui::layout::Layout::default() .direction(Direction::Vertical) .margin(0) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) .split(rect); - let top_quarters = ::ratatui::layout::Layout::default() + let top_quarters = ratatui::layout::Layout::default() .direction(Direction::Horizontal) .margin(0) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) diff --git a/src/display/components/table.rs b/src/display/components/table.rs index ccfd9c5..a000e91 100644 --- a/src/display/components/table.rs +++ b/src/display/components/table.rs @@ -1,17 +1,22 @@ -use ::std::collections::{BTreeMap, HashMap}; -use ::std::iter::FromIterator; -use ::unicode_width::UnicodeWidthChar; +use std::{ + collections::{BTreeMap, HashMap}, + iter::FromIterator, + net::IpAddr, +}; -use ::ratatui::backend::Backend; -use ::ratatui::layout::{Constraint, Rect}; -use ::ratatui::style::{Color, Style}; -use ::ratatui::terminal::Frame; -use ::ratatui::widgets::{Block, Borders, Row}; +use ratatui::{ + backend::Backend, + layout::{Constraint, Rect}, + style::{Color, Style}, + terminal::Frame, + widgets::{Block, Borders, Row}, +}; +use unicode_width::UnicodeWidthChar; -use crate::display::{Bandwidth, DisplayBandwidth, UIState}; -use crate::network::{display_connection_string, display_ip_or_host}; - -use ::std::net::IpAddr; +use crate::{ + display::{Bandwidth, DisplayBandwidth, UIState}, + network::{display_connection_string, display_ip_or_host}, +}; fn display_upload_and_download(bandwidth: &impl Bandwidth, total: bool) -> String { format!( @@ -292,7 +297,7 @@ impl<'a> Table<'a> { let table_rows = rows.map(|row| Row::new(row).style(Style::default())); let width_constraints: Vec<Constraint> = widths.iter().map(|w| Constraint::Length(*w)).collect(); - let table = ::ratatui::widgets::Table::new(table_rows) + let table = ratatui::widgets::Table::new(table_rows) .block(Block::default().title(self.title).borders(Borders::ALL)) .header(Row::new(column_names).style(Style::default().fg(Color::Yellow))) .widths(&width_constraints) diff --git a/src/display/raw_terminal_backend.rs b/src/display/raw_terminal_backend.rs index 48b4b50..fc08abc 100644 --- a/src/display/raw_terminal_backend.rs +++ b/src/display/raw_terminal_backend.rs @@ -7,10 +7,10 @@ // that implements the Backend TUI trait, but does nothing // this way, we don't need to create the TermionBackend // and thus skew our stdout when we don't need it -use ::ratatui::backend::Backend; -use ::ratatui::buffer::Cell; -use ::ratatui::layout::Rect; -use ::std::io; + +use std::io; + +use ratatui::{backend::Backend, buffer::Cell, layout::Rect}; pub struct RawTerminalBackend {} diff --git a/src/display/ui.rs b/src/display/ui.rs index 111dfe1..54811b8 100644 --- a/src/display/ui.rs +++ b/src/display/ui.rs @@ -1,17 +1,16 @@ -use ::std::collections::HashMap; +use std::{collections::HashMap, net::IpAddr, time::Duration}; -use ::ratatui::backend::Backend; -use ::ratatui::Terminal; - -use crate::display::components::{HeaderDetails, HelpText, Layout, Table}; -use crate::display::UIState; -use crate::network::{display_connection_string, display_ip_or_host, LocalSocket, Utilization}; - -use ::std::net::IpAddr; - -use crate::RenderOpts; use chrono::prelude::*; -use std::time::Duration; +use ratatui::{backend::Backend, Terminal}; + +use crate::{ + display::{ + components::{HeaderDetails, HelpText, Layout, Table}, + UIState, + }, + network::{display_connection_string, display_ip_or_host, LocalSocket, Utilization}, + RenderOpts, +}; pub struct Ui<B> where diff --git a/src/display/ui_state.rs b/src/display/ui_state.rs index c992808..41fbbda 100644 --- a/src/display/ui_state.rs +++ b/src/display/ui_state.rs @@ -1,8 +1,10 @@ -use ::std::cmp; -use ::std::collections::{HashMap, HashSet, VecDeque}; -use ::std::hash::Hash; -use ::std::iter::FromIterator; -use ::std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; +use std::{ + cmp, + collections::{HashMap, HashSet, VecDeque}, + hash::Hash, + iter::FromIterator, + net::{IpAddr, Ipv4Addr, Ipv6Addr}, +}; use crate::network::{Connection, LocalSocket, Utilization}; diff --git a/src/main.rs b/src/main.rs index 8d88ec1..53b3e7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,28 +6,29 @@ mod os; #[cfg(test)] mod tests; +use std::{ + collections::HashMap, + net::Ipv4Addr, + process, + sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, Mutex, RwLock, + }, + thread::{self, park_timeout}, + time::{Duration, Instant}, +}; + +use crossterm::{ + event::{Event, KeyCode, KeyEvent, KeyModifiers}, + terminal, +}; use display::{elapsed_time, RawTerminalBackend, Ui}; use network::{ dns::{self, IpTable}, LocalSocket, Sniffer, Utilization, }; - -use ::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; -use ::crossterm::terminal; -use ::pnet::datalink::{DataLinkReceiver, NetworkInterface}; -use ::ratatui::backend::Backend; -use ::std::collections::HashMap; -use ::std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; -use ::std::sync::{Arc, Mutex}; -use ::std::thread; -use ::std::thread::park_timeout; - -use std::process; - -use ::ratatui::backend::CrosstermBackend; -use ::std::net::Ipv4Addr; -use ::std::time::{Duration, Instant}; -use std::sync::RwLock; +use pnet::datalink::{DataLinkReceiver, NetworkInterface}; +use ratatui::backend::{Backend, CrosstermBackend}; use structopt::StructOpt; const DISPLAY_DELTA: Duration = Duration::from_millis(1000); diff --git a/src/network/connection.rs b/src/network/connection.rs index c0c35ea..780eafa 100644 --- a/src/network/connection.rs +++ b/src/network/connection.rs @@ -1,8 +1,8 @@ -use ::std::collections::HashMap; -use ::std::fmt; -use ::std::net::IpAddr; - -use ::std::net::SocketAddr; +use std::{ + collections::HashMap, + fmt, + net::{IpAddr, SocketAddr}, +}; #[derive(PartialEq, Hash, Eq, Clone, PartialOrd, Ord, Debug, Copy)] pub enum Protocol { @@ -11,10 +11,7 @@ pub enum Protocol { } impl Protocol { - // Currently, linux implementation doesn't use this function. - // Without this #[cfg] clippy complains about dead code, and CI refuses - // to pass. - #[cfg(any(target_os = "macos", target_os = "freebsd"))] + #[allow(dead_code)] pub fn from_str(string: &str) -> Option<Self> { match string { "TCP" => Some(Protocol::Tcp), diff --git a/src/network/dns/client.rs b/src/network/dns/client.rs index ec47d50..0adb787 100644 --- a/src/network/dns/client.rs +++ b/src/network/dns/client.rs @@ -1,15 +1,17 @@ -use crate::network::dns::{resolver::Lookup, IpTable}; use std::{ collections::HashSet, net::IpAddr, sync::{Arc, Mutex}, thread::{Builder, JoinHandle}, }; + use tokio::{ runtime::Runtime, sync::mpsc::{self, Sender}, }; +use crate::network::dns::{resolver::Lookup, IpTable}; + type PendingAddrs = HashSet<IpAddr>; const CHANNEL_SIZE: usize = 1_000; diff --git a/src/network/dns/resolver.rs b/src/network/dns/resolver.rs index 4c43975..c8a19f7 100644 --- a/src/network/dns/resolver.rs +++ b/src/network/dns/resolver.rs @@ -1,9 +1,11 @@ +use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}; + use async_trait::async_trait; -use std::net::IpAddr; -use std::net::SocketAddr; -use std::net::{Ipv4Addr, SocketAddrV4}; -use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts}; -use trust_dns_resolver::{error::ResolveErrorKind, TokioAsyncResolver}; +use trust_dns_resolver::{ + config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts}, + error::ResolveErrorKind, + TokioAsyncResolver, +}; #[async_trait] pub trait Lookup { diff --git a/src/network/sniffer.rs b/src/network/sniffer.rs index de587be..5409185 100644 --- a/src/network/sniffer.rs +++ b/src/network/sniffer.rs @@ -1,24 +1,31 @@ -use ::std::boxed::Box; - -use ::pnet::datalink::{DataLinkReceiver, NetworkInterface}; -use ::pnet::packet::ethernet::{EtherTypes, EthernetPacket}; -use ::pnet::packet::ip::{IpNextHeaderProtocol, IpNextHeaderProtocols}; -use ::pnet::packet::ipv4::Ipv4Packet; -use ::pnet::packet::ipv6::Ipv6Packet; -use ::pnet::packet::tcp::TcpPacket; -use ::pnet::packet::udp::UdpPacket; -use ::pnet::packet::Packet; - -use ::ipnetwork::IpNetwork; -use ::std::io::{self, Result}; -use ::std::net::{IpAddr, SocketAddr}; -use ::std::thread::park_timeout; - -use crate::network::{Connection, Protocol}; -use crate::os::shared::get_datalink_channel; - -const PACKET_WAIT_TIMEOUT: std::time::Duration = std::time::Duration::from_millis(10); -const CHANNEL_RESET_DELAY: std::time::Duration = std::time::Duration::from_millis(1000); +use std::{ + io::{self, Result}, + net::{IpAddr, SocketAddr}, + thread::park_timeout, + time::Duration, +}; + +use ipnetwork::IpNetwork; +use pnet::{ + datalink::{DataLinkReceiver, NetworkInterface}, + packet::{ + ethernet::{EtherTypes, EthernetPacket}, + ip::{IpNextHeaderProtocol, IpNextHeaderProtocols}, + ipv4::Ipv4Packet, + ipv6::Ipv6Packet, + tcp::TcpPacket, + udp::UdpPacket, + Packet, + }, +}; + +use crate::{ + network::{Connection, Protocol}, + os::shared::get_datalink_channel, +}; + +const PACKET_WAIT_TIMEOUT: Duration = Duration::from_millis(10); +const CHANNEL_RESET_DELAY: Duration = Duration::from_millis(1000); #[derive(Debug)] pub struct Segment { diff --git a/src/network/utilization.rs b/src/network/utilization.rs index bdfbb21..c44356b 100644 --- a/src/network/utilization.rs +++ b/src/network/utilization.rs @@ -1,6 +1,6 @@ -use crate::network::{Connection, Direction, Segment}; +use std::collections::HashMap; -use ::std::collections::HashMap; +use crate::network::{Connection, Direction, Segment}; #[derive(Clone)] pub struct ConnectionInfo { diff --git a/src/os/linux.rs b/src/os/linux.rs index 5dd5c2b..d1813ab 100644 --- a/src/os/linux.rs +++ b/src/os/linux.rs @@ -1,9 +1,11 @@ -use ::std::collections::HashMap; +use std::collections::HashMap; -use ::procfs::process::FDTarget; +use procfs::process::FDTarget; -use crate::network::{LocalSocket, Protocol}; -use crate::OpenSockets; +use crate::{ + network::{LocalSocket, Protocol}, + OpenSockets, +}; pub(crate) fn get_open_sockets() -> OpenSockets { let mut open_sockets = HashMap::new(); @@ -22,8 +24,8 @@ pub(crate) fn get_open_sockets() -> OpenSockets { } } - if let Ok(mut tcp) = ::procfs::net::tcp() { - if let Ok(mut tcp6) = ::procfs::net::tcp6() { + if let Ok(mut tcp) = procfs::net::tcp() { + if let Ok(mut tcp6) = procfs::net::tcp6() { tcp.append(&mut tcp6); } for entry in tcp.into_iter() { @@ -40,8 +42,8 @@ pub(crate) fn get_open_sockets() -> OpenSockets { } } - if let Ok(mut udp) = ::procfs::net::udp() { - if let Ok(mut udp6) = ::procfs::net::udp6() { + if let Ok(mut udp) = procfs::net::udp() { + if let Ok(mut udp6) = procfs::net::udp6() { udp.append(&mut udp6); } for entry in udp.into_iter() { diff --git a/src/os/lsof.rs b/src/os/lsof.rs index 77331ed..f6d1e3f 100644 --- a/src/os/lsof.rs +++ b/src/os/lsof.rs @@ -1,14 +1,11 @@ -use ::std::collections::HashMap; +use std::collections::HashMap; -use crate::network::LocalSocket; -use crate::OpenSockets; - -use super::lsof_utils; +use crate::{network::LocalSocket, os::lsof_utils::get_connections, OpenSockets}; pub(crate) fn get_open_sockets() -> OpenSockets { let mut open_sockets = HashMap::new(); - let connections = lsof_utils::get_connections(); + let connections = get_connections(); for raw_connection in connections { open_sockets.insert( diff --git a/src/os/lsof_utils.rs b/src/os/lsof_utils.rs index 46fe8fc..5e5b8c9 100644 --- a/src/os/lsof_utils.rs +++ b/src/os/lsof_utils.rs @@ -1,9 +1,9 @@ -use crate::network::Protocol; +use std::{ffi::OsStr, net::IpAddr, process::Command}; + use lazy_static::lazy_static; use regex::Regex; -use std::ffi::OsStr; -use std::net::IpAddr; -use std::process::Command; + +use crate::network::Protocol; #[allow(dead_code)] #[derive(Debug, Clone)] diff --git a/src/os/shared.rs b/src/os/shared.rs index f8d997d..ee3415a 100644 --- a/src/os/shared.rs +++ b/src/os/shared.rs @@ -1,15 +1,14 @@ -use ::crossterm::event::read; -use ::crossterm::event::Event; -use ::pnet::datalink::Channel::Ethernet; -use ::pnet::datalink::DataLinkReceiver; -use ::pnet::datalink::{self, Config, NetworkInterface}; -use ::std::io::{self, ErrorKind, Write}; -use ::tokio::runtime::Runtime; +use std::{ + io::{self, ErrorKind, Write}, + net::Ipv4Addr, + time, +}; -use ::std::net::Ipv4Addr; -use ::std::time; +use crossterm::event::{read, Event}; +use pnet::datalink::{self, Channel::Ethernet, Config, DataLinkReceiver, NetworkInterface}; +use tokio::runtime::Runtime; -use crate::os::errors::GetInterfaceError; +use crate::{network::dns, os::errors::GetInterfaceError, OsInputOutput}; #[cfg(target_os = "linux")] use crate::os::linux::get_open_sockets; @@ -18,8 +17,6 @@ use crate::os::lsof::get_open_sockets; #[cfg(target_os = "windows")] use crate::os::windows::get_open_sockets; -use crate::{network::dns, OsInputOutput}; - pub struct TerminalEvents; impl Iterator for TerminalEvents { diff --git a/src/os/windows.rs b/src/os/windows.rs index 5bb6118..5c72400 100644 --- a/src/os/windows.rs +++ b/src/os/windows.rs @@ -3,8 +3,10 @@ use std::collections::HashMap; use netstat2::*; use sysinfo::{Pid, PidExt, ProcessExt, System, SystemExt}; -use crate::network::{LocalSocket, Protocol}; -use crate::OpenSockets; +use crate::{ + network::{LocalSocket, Protocol}, + OpenSockets, +}; pub(crate) fn get_open_sockets() -> OpenSockets { let mut open_sockets = HashMap::new(); diff --git a/src/tests/cases/raw_mode.rs b/src/tests/cases/raw_mode.rs index 6da54ab..c382a2b 100644 --- a/src/tests/cases/raw_mode.rs +++ b/src/tests/cases/raw_mode.rs @@ -1,20 +1,25 @@ -use crate::tests::fakes::{create_fake_dns_client, NetworkFrames}; - -use ::insta::assert_snapshot; -use ::std::sync::{Arc, Mutex}; - -use ::std::collections::HashMap; -use ::std::net::IpAddr; +use std::{ + collections::HashMap, + net::IpAddr, + sync::{Arc, Mutex}, +}; +use insta::assert_snapshot; use packet_builder::*; use pnet::{datalink::DataLinkReceiver, packet::Packet}; -use crate::tests::cases::test_utils::{ - build_tcp_packet, opts_raw, os_input_output_dns, os_input_output_stdout, test_backend_factory, +use crate::{ + start, + tests::{ + cases::test_utils::{ + build_tcp_packet, opts_raw, os_input_output_dns, os_input_output_stdout, + test_backend_factory, + }, + fakes::{create_fake_dns_client, NetworkFrames}, + }, + Opt, RenderOpts, }; -use crate::{start, Opt, RenderOpts}; - fn build_ip_tcp_packet( source_ip: &str, destination_ip: &str, diff --git a/src/tests/cases/test_utils.rs b/src/tests/cases/test_utils.rs index 1137157..d2df990 100644 --- a/src/tests/cases/test_utils.rs +++ b/src/tests/cases/test_utils.rs @@ -1,21 +1,24 @@ -use crate::tests::fakes::{ - create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames, TerminalEvent, - TerminalEvents, TestBackend, +use std::{ + collections::HashMap, + io::Write, + iter, + sync::{Arc, Mutex}, }; -use std::iter; -use crate::network::dns::Client; -use crate::{Opt, OsInputOutput, RenderOpts}; -use ::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; +use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; use packet_builder::*; -use pnet::datalink::DataLinkReceiver; -use std::collections::HashMap; -use std::io::Write; -use std::sync::{Arc, Mutex}; - -use pnet::packet::Packet; +use pnet::{datalink::DataLinkReceiver, packet::Packet}; use pnet_base::MacAddr; +use crate::{ + network::dns::Client, + tests::fakes::{ + create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames, TerminalEvent, + TerminalEvents, TestBackend, + }, + Opt, OsInputOutput, RenderOpts, +}; + pub fn sleep_and_quit_events(sleep_num: usize) -> Box<TerminalEvents> { let mut events: Vec<Option<Event>> = iter::repeat(None).take(sleep_num).collect(); events.push(Some(Event::Key(KeyEvent::new( diff --git a/src/tests/cases/ui.rs b/src/tests/cases/ui.rs index 065e543..bf2779b 100644 --- a/src/tests/cases/ui.rs +++ b/src/tests/cases/ui.rs @@ -1,24 +1,23 @@ -use crate::tests::fakes::TerminalEvent::*; -use crate::tests::fakes::{ - create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames, -}; - -use ::insta::assert_snapshot; +use std::{collections::HashMap, iter, net::IpAddr}; -use ::std::collections::HashMap; -use ::std::net::IpAddr; - -use crate::tests::cases::test_utils::{ - build_tcp_packet, opts_ui, os_input_output, os_input_output_factory, sample_frames, - sleep_and_quit_events, sleep_resize_and_quit_events, test_backend_factory, -}; -use ::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; +use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; +use insta::assert_snapshot; use pnet::datalink::DataLinkReceiver; -use std::iter; -use crate::tests::fakes::TerminalEvents; - -use crate::{start, Opt, OsInputOutput, RenderOpts}; +use crate::{ + start, + tests::{ + cases::test_utils::{ + build_tcp_packet, opts_ui, os_input_output, os_input_output_factory, sample_frames, + sleep_and_quit_events, sleep_resize_and_quit_events, test_backend_factory, + }, + fakes::{ + create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames, + TerminalEvent::*, TerminalEvents, + }, + }, + Opt, OsInputOutput, RenderOpts, +}; #[test] fn basic_startup() { diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs index 462ceb6..e064b7e 100644 --- a/src/tests/fakes/fake_input.rs +++ b/src/tests/fakes/fake_input.rs @@ -1,12 +1,14 @@ -use ::async_trait::async_trait; -use ::crossterm::event::Event; -use ::ipnetwork::IpNetwork; -use ::pnet::datalink::DataLinkReceiver; -use ::pnet::datalink::NetworkInterface; -use ::std::collections::HashMap; -use ::std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use ::std::{thread, time}; -use ::tokio::runtime::Runtime; +use std::{ + collections::HashMap, + net::{IpAddr, Ipv4Addr, SocketAddr}, + thread, time, +}; + +use async_trait::async_trait; +use crossterm::event::Event; +use ipnetwork::IpNetwork; +use pnet::datalink::{DataLinkReceiver, NetworkInterface}; +use tokio::runtime::Runtime; use crate::{ network::{ diff --git a/src/tests/fakes/fake_output.rs b/src/tests/fakes/fake_output.rs index dd345e4..ac6f3cd 100644 --- a/src/tests/fakes/fake_output.rs +++ b/src/tests/fakes/fake_output.rs @@ -1,9 +1,10 @@ -use ::ratatui::backend::Backend; -use ::ratatui::buffer::Cell; -use ::ratatui::layout::Rect; -use ::std::collections::HashMap; -use ::std::io; -use ::std::sync::{Arc, Mutex}; +use std::{ + collections::HashMap, + io, + sync::{Arc, Mutex}, +}; + +use ratatui::{backend::Backend, buffer::Cell, layout::Rect}; #[derive(Hash, Debug, PartialEq)] pub enum TerminalEvent { |