diff options
-rw-r--r-- | src/cli.rs | 4 | ||||
-rw-r--r-- | src/tests/cases/raw_mode.rs | 10 | ||||
-rw-r--r-- | src/tests/cases/test_utils.rs | 24 | ||||
-rw-r--r-- | src/tests/cases/ui.rs | 87 |
4 files changed, 28 insertions, 97 deletions
@@ -2,7 +2,7 @@ use std::net::Ipv4Addr; use clap::{Args, Parser}; -#[derive(Parser, Debug)] +#[derive(Clone, Debug, Default, Parser)] #[command(name = "bandwhich", version)] pub struct Opt { #[arg(short, long)] @@ -29,7 +29,7 @@ pub struct Opt { pub render_opts: RenderOpts, } -#[derive(Args, Debug, Copy, Clone)] +#[derive(Copy, Clone, Debug, Default, Args)] pub struct RenderOpts { #[arg(short, long)] /// Show processes table only diff --git a/src/tests/cases/raw_mode.rs b/src/tests/cases/raw_mode.rs index 1315e53..5108a66 100644 --- a/src/tests/cases/raw_mode.rs +++ b/src/tests/cases/raw_mode.rs @@ -9,7 +9,6 @@ use packet_builder::*; use pnet::{datalink::DataLinkReceiver, packet::Packet}; use crate::{ - cli::RenderOpts, start, tests::{ cases::test_utils::{ @@ -580,14 +579,7 @@ fn no_resolve_mode() { interface: Some(String::from("interface_name")), raw: true, no_resolve: true, - show_dns: false, - dns_server: None, - render_opts: RenderOpts { - addresses: false, - connections: false, - processes: false, - total_utilization: false, - }, + ..Default::default() }; start(backend, os_input, opts); let stdout = Arc::try_unwrap(stdout).unwrap().into_inner().unwrap(); diff --git a/src/tests/cases/test_utils.rs b/src/tests/cases/test_utils.rs index 1e70bbe..4c1d422 100644 --- a/src/tests/cases/test_utils.rs +++ b/src/tests/cases/test_utils.rs @@ -12,7 +12,6 @@ use pnet_base::MacAddr; use rstest::fixture; use crate::{ - cli::RenderOpts, network::dns::Client, tests::fakes::{ create_fake_dns_client, get_interfaces, get_open_sockets, NetworkFrames, TerminalEvent, @@ -269,28 +268,19 @@ pub fn os_input_output_factory( } pub fn opts_raw() -> Opt { - opts_factory(true) + Opt { + interface: Some(String::from("interface_name")), + raw: true, + ..Default::default() + } } - pub fn opts_ui() -> Opt { - opts_factory(false) -} - -fn opts_factory(raw: bool) -> Opt { Opt { interface: Some(String::from("interface_name")), - raw, - no_resolve: false, - show_dns: false, - dns_server: None, - render_opts: RenderOpts { - addresses: false, - connections: false, - processes: false, - total_utilization: false, - }, + ..Default::default() } } + type BackendWithStreams = ( Arc<Mutex<Vec<TerminalEvent>>>, Arc<Mutex<Vec<String>>>, diff --git a/src/tests/cases/ui.rs b/src/tests/cases/ui.rs index b8717e3..01fe8d1 100644 --- a/src/tests/cases/ui.rs +++ b/src/tests/cases/ui.rs @@ -156,17 +156,11 @@ fn basic_only_processes() { let (_, terminal_draw_events, backend) = test_backend_factory(190, 50); let os_input = os_input_output(network_frames, 1); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, - show_dns: false, - dns_server: None, render_opts: RenderOpts { - addresses: false, - connections: false, processes: true, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); @@ -183,17 +177,12 @@ fn basic_processes_with_dns_queries() { let (_, terminal_draw_events, backend) = test_backend_factory(190, 50); let os_input = os_input_output(network_frames, 1); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, show_dns: true, - dns_server: None, render_opts: RenderOpts { - addresses: false, - connections: false, processes: true, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); @@ -210,17 +199,11 @@ fn basic_only_connections() { let (_, terminal_draw_events, backend) = test_backend_factory(190, 50); let os_input = os_input_output(network_frames, 1); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, - show_dns: false, - dns_server: None, render_opts: RenderOpts { - addresses: false, connections: true, - processes: false, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); @@ -237,17 +220,11 @@ fn basic_only_addresses() { let (_, terminal_draw_events, backend) = test_backend_factory(190, 50); let os_input = os_input_output(network_frames, 1); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, - show_dns: false, - dns_server: None, render_opts: RenderOpts { addresses: true, - connections: false, - processes: false, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); @@ -260,17 +237,11 @@ fn two_packets_only_processes(frames: Vec<Box<dyn DataLinkReceiver>>) { let (_, terminal_draw_events, backend) = test_backend_factory(190, 50); let os_input = os_input_output(frames, 2); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, - show_dns: false, - dns_server: None, render_opts: RenderOpts { - addresses: false, - connections: false, processes: true, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); @@ -284,17 +255,11 @@ fn two_packets_only_connections(frames: Vec<Box<dyn DataLinkReceiver>>) { let (_, terminal_draw_events, backend) = test_backend_factory(190, 50); let os_input = os_input_output(frames, 2); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, - show_dns: false, - dns_server: None, render_opts: RenderOpts { - addresses: false, connections: true, - processes: false, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); @@ -308,17 +273,11 @@ fn two_packets_only_addresses(frames: Vec<Box<dyn DataLinkReceiver>>) { let (_, terminal_draw_events, backend) = test_backend_factory(190, 50); let os_input = os_input_output(frames, 2); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, - show_dns: false, - dns_server: None, render_opts: RenderOpts { addresses: true, - connections: false, - processes: false, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); @@ -336,17 +295,12 @@ fn two_windows_split_horizontally() { let (_, terminal_draw_events, backend) = test_backend_factory(60, 50); let os_input = os_input_output(network_frames, 2); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, - show_dns: false, - dns_server: None, render_opts: RenderOpts { addresses: true, connections: true, - processes: false, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); @@ -363,17 +317,12 @@ fn two_windows_split_vertically() { let (_, terminal_draw_events, backend) = test_backend_factory(190, 50); let os_input = os_input_output(network_frames, 1); let opts = Opt { - interface: Some(String::from("interface_name")), - raw: false, - no_resolve: false, - show_dns: false, - dns_server: None, render_opts: RenderOpts { addresses: true, connections: true, - processes: false, - total_utilization: false, + ..Default::default() }, + ..opts_ui() }; start(backend, os_input, opts); |