From 72b04c82aec4a21fabe1bf694d56f44eb5cae193 Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Sat, 7 Oct 2023 22:13:14 +0800 Subject: Compact tests using `rstest` --- Cargo.lock | 106 +++ Cargo.toml | 1 + ...s__cases__ui__full-width-under-30-height-0.snap | 34 + ...s__cases__ui__full-width-under-30-height-1.snap | 34 + ...s__ui__layout_full_width_under_30_height-2.snap | 34 - ...ses__ui__layout_full_width_under_30_height.snap | 34 - ...__ui__layout_under_120_width_full_height-2.snap | 55 -- ...es__ui__layout_under_120_width_full_height.snap | 55 -- ...__layout_under_120_width_under_30_height-2.snap | 34 - ...ui__layout_under_120_width_under_30_height.snap | 34 - ...i__layout_under_50_width_under_50_height-2.snap | 55 -- ..._ui__layout_under_50_width_under_50_height.snap | 55 -- ...i__layout_under_70_width_under_30_height-2.snap | 34 - ..._ui__layout_under_70_width_under_30_height.snap | 34 - ...__cases__ui__under-120-width-full-height-0.snap | 55 ++ ...__cases__ui__under-120-width-full-height-1.snap | 55 ++ ...ses__ui__under-120-width-under-30-height-0.snap | 34 + ...ses__ui__under-120-width-under-30-height-1.snap | 34 + ...ases__ui__under-50-width-under-50-height-0.snap | 55 ++ ...ases__ui__under-50-width-under-50-height-1.snap | 55 ++ ...ases__ui__under-70-width-under-30-height-0.snap | 34 + ...ases__ui__under-70-width-under-30-height-1.snap | 34 + src/tests/cases/test_utils.rs | 123 +++- src/tests/cases/ui.rs | 708 ++------------------- 24 files changed, 707 insertions(+), 1079 deletions(-) create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__full-width-under-30-height-0.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__full-width-under-30-height-1.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_full_width_under_30_height-2.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_full_width_under_30_height.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_full_height-2.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_full_height.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_under_30_height-2.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_under_30_height.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_50_width_under_50_height-2.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_50_width_under_50_height.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_70_width_under_30_height-2.snap delete mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_70_width_under_30_height.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__under-120-width-full-height-0.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__under-120-width-full-height-1.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__under-120-width-under-30-height-0.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__under-120-width-under-30-height-1.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__under-50-width-under-50-height-0.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__under-50-width-under-50-height-1.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__under-70-width-under-30-height-0.snap create mode 100644 src/tests/cases/snapshots/bandwhich__tests__cases__ui__under-70-width-under-30-height-1.snap diff --git a/Cargo.lock b/Cargo.lock index 92266e6..5992270 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,6 +162,7 @@ dependencies = [ "ratatui", "regex", "resolv-conf", + "rstest", "sysinfo", "thiserror", "tokio", @@ -567,6 +568,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.28" @@ -574,6 +590,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -582,26 +599,65 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + [[package]] name = "futures-task" version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +[[package]] +name = "futures-timer" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" + [[package]] name = "futures-util" version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", @@ -1375,6 +1431,12 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +[[package]] +name = "relative-path" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" + [[package]] name = "resolv-conf" version = "0.7.0" @@ -1385,12 +1447,50 @@ dependencies = [ "quick-error", ] +[[package]] +name = "rstest" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97eeab2f3c0a199bc4be135c36c924b6590b88c377d416494288c14f2db30199" +dependencies = [ + "futures", + "futures-timer", + "rstest_macros", + "rustc_version", +] + +[[package]] +name = "rstest_macros" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d428f8247852f894ee1be110b375111b586d4fa431f6c46e64ba5a0dcccbe605" +dependencies = [ + "cfg-if", + "glob", + "proc-macro2", + "quote", + "regex", + "relative-path", + "rustc_version", + "syn 2.0.38", + "unicode-ident", +] + [[package]] name = "rustc-demangle" version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.36.15" @@ -1462,6 +1562,12 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" + [[package]] name = "serde" version = "1.0.188" diff --git a/Cargo.toml b/Cargo.toml index 8ca5c93..48dad19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ procfs = "0.15.1" insta = "1.33.0" pnet_base = "0.34.0" packet-builder = { version = "0.7.0", git = "https://github.com/cyqsimon/packet_builder.git", branch = "patch-update" } +rstest = "0.18.2" [target.'cfg(target_os="windows")'.build-dependencies] anyhow = "1.0.75" diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__full-width-under-30-height-0.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__full-width-under-30-height-0.snap new file mode 100644 index 0000000..1e26e22 --- /dev/null +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__full-width-under-30-height-0.snap @@ -0,0 +1,34 @@ +--- +source: src/tests/cases/ui.rs +expression: "&terminal_draw_events_mirror[0]" +--- + Total Up / Down: 0Bps / 0Bps +┌Utilization by process name──────────────────────────────────────────────────────────────────┐┌Utilization by remote address────────────────────────────────────────────────────────────────┐ +│Process Connections Up / Down ││Remote Address Connections Up / Down │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└─────────────────────────────────────────────────────────────────────────────────────────────┘└─────────────────────────────────────────────────────────────────────────────────────────────┘ + Press to pause. Use to rearrange tables. (DNS queries hidden). + diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__full-width-under-30-height-1.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__full-width-under-30-height-1.snap new file mode 100644 index 0000000..9c60b32 --- /dev/null +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__full-width-under-30-height-1.snap @@ -0,0 +1,34 @@ +--- +source: src/tests/cases/ui.rs +expression: "&terminal_draw_events_mirror[1]" +--- + 98Bps + + + 5 1 0Bps / 28Bps 3.3.3.3 1 0Bps / 28Bps + 4 1 0Bps / 26Bps 2.2.2.2 1 0Bps / 26Bps + 1 1 0Bps / 22Bps 1.1.1.1 1 0Bps / 22Bps + 2 1 0Bps / 21Bps 4.4.4.4 1 0Bps / 21Bps + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_full_width_under_30_height-2.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_full_width_under_30_height-2.snap deleted file mode 100644 index 9c60b32..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_full_width_under_30_height-2.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: src/tests/cases/ui.rs -expression: "&terminal_draw_events_mirror[1]" ---- - 98Bps - - - 5 1 0Bps / 28Bps 3.3.3.3 1 0Bps / 28Bps - 4 1 0Bps / 26Bps 2.2.2.2 1 0Bps / 26Bps - 1 1 0Bps / 22Bps 1.1.1.1 1 0Bps / 22Bps - 2 1 0Bps / 21Bps 4.4.4.4 1 0Bps / 21Bps - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_full_width_under_30_height.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_full_width_under_30_height.snap deleted file mode 100644 index 1e26e22..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_full_width_under_30_height.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: src/tests/cases/ui.rs -expression: "&terminal_draw_events_mirror[0]" ---- - Total Up / Down: 0Bps / 0Bps -┌Utilization by process name──────────────────────────────────────────────────────────────────┐┌Utilization by remote address────────────────────────────────────────────────────────────────┐ -│Process Connections Up / Down ││Remote Address Connections Up / Down │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -│ ││ │ -└─────────────────────────────────────────────────────────────────────────────────────────────┘└─────────────────────────────────────────────────────────────────────────────────────────────┘ - Press to pause. Use to rearrange tables. (DNS queries hidden). - diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_full_height-2.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_full_height-2.snap deleted file mode 100644 index 8230e66..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_full_height-2.snap +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: src/tests/cases/ui.rs -expression: "&terminal_draw_events_mirror[1]" ---- - 98Bps - - - 5 1 0Bps / 28Bps - 4 1 0Bps / 26Bps - 1 1 0Bps / 22Bps - 2 1 0Bps / 21Bps - - - - - - - - - - - - - - - - - - - - - 3.3.3.3 1 0Bps / 28Bps - 2.2.2.2 1 0Bps / 26Bps - 1.1.1.1 1 0Bps / 22Bps - 4.4.4.4 1 0Bps / 21Bps - - - - - - - - - - - - - - - - - - - - diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_full_height.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_full_height.snap deleted file mode 100644 index 53043a7..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_full_height.snap +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: src/tests/cases/ui.rs -expression: "&terminal_draw_events_mirror[0]" ---- - Total Up / Down: 0Bps / 0Bps -┌Utilization by process name──────────────────────────────────────────────────────────────────────────────────────────┐ -│Process Connections Up / Down │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ -┌Utilization by remote address────────────────────────────────────────────────────────────────────────────────────────┐ -│Remote Address Connections Up / Down │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ - Press to pause. Use to rearrange tables. (DNS queries hidden). - diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_under_30_height-2.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_under_30_height-2.snap deleted file mode 100644 index 06cb645..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_under_30_height-2.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: src/tests/cases/ui.rs -expression: "&terminal_draw_events_mirror[1]" ---- - 98Bps - - - 5 1 0Bps / 28Bps - 4 1 0Bps / 26Bps - 1 1 0Bps / 22Bps - 2 1 0Bps / 21Bps - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_under_30_height.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_under_30_height.snap deleted file mode 100644 index 0bbc796..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_120_width_under_30_height.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: src/tests/cases/ui.rs -expression: "&terminal_draw_events_mirror[0]" ---- - Total Up / Down: 0Bps / 0Bps -┌Utilization by process name──────────────────────────────────────────────────────────────────────────────────────────┐ -│Process Connections Up / Down │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ - Press to pause. Use to rearrange tables. (DNS queries hidden). - diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_50_width_under_50_height-2.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_50_width_under_50_height-2.snap deleted file mode 100644 index b7493b4..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_50_width_under_50_height-2.snap +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: src/tests/cases/ui.rs -assertion_line: 1580 -expression: "&terminal_draw_events_mirror[1]" ---- - 98Bps - - - 5 0Bps / 28Bps - 4 0Bps / 26Bps - 1 0Bps / 22Bps - 2 0Bps / 21Bps - - - - - - - - - - - - - - - - - - - - - 3.3.3.3 0Bps / 28Bps - 2.2.2.2 0Bps / 26Bps - 1.1.1.1 0Bps / 22Bps - 4.4.4.4 0Bps / 21Bps - - - - - - - - - - - - - - - - - - - diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_50_width_under_50_height.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_50_width_under_50_height.snap deleted file mode 100644 index 15cfa04..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_50_width_under_50_height.snap +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: src/tests/cases/ui.rs -assertion_line: 1579 -expression: "&terminal_draw_events_mirror[0]" ---- - Total Up / Down: 0Bps / 0Bps -┌Utilization by process name────────────────────┐ -│Process Up / Down │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└───────────────────────────────────────────────┘ -┌Utilization by remote address──────────────────┐ -│Remote Address Up / Down │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└───────────────────────────────────────────────┘ - Press to pause. - diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_70_width_under_30_height-2.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_70_width_under_30_height-2.snap deleted file mode 100644 index 6f24434..0000000 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout_under_70_width_under_30_height-2.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: src/tests/cases/ui.rs -expression: "&terminal_draw_events_mirror[1]" ---- - 98Bps - - - 5 1 0Bps / 28Bps - 4 1 0Bps / 26Bps - 1 1 0Bps / 22Bps - 2 1 0Bps / 21Bps - -