From 036b319f8e4ab2a26911a93745d885cc773a4983 Mon Sep 17 00:00:00 2001 From: Francisco Jimenez Cabrera Date: Fri, 31 May 2024 19:10:54 +0100 Subject: [PATCH 1/2] Fix tests and release v1.1.0 --- .github/workflows/tests.yml | 7 +++++-- Cargo.toml | 2 +- snapcraft.yaml | 2 +- tests/killport_unix_tests.rs | 3 +-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d2e40a8..241a2d5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,10 @@ on: jobs: test: - runs-on: macos-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] steps: - name: Checkout repository uses: actions/checkout@v2 @@ -22,4 +25,4 @@ jobs: override: true - name: Run tests - run: cargo test --all + run: cargo test --tests -- --test-threads=1 diff --git a/Cargo.toml b/Cargo.toml index 09883e1..d310b55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "killport" -version = "1.0.0" +version = "1.1.0" authors = ["Francisco Jimenez Cabrera "] edition = "2021" license = "MIT" diff --git a/snapcraft.yaml b/snapcraft.yaml index 35c3415..dbc08be 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1,5 +1,5 @@ name: killport -version: "1.0.0" +version: "1.1.0" summary: A CLI tool to kill processes using specified ports description: | Killport is a command-line utility to find and kill processes listening on specified ports. diff --git a/tests/killport_unix_tests.rs b/tests/killport_unix_tests.rs index f2f0af7..a307129 100644 --- a/tests/killport_unix_tests.rs +++ b/tests/killport_unix_tests.rs @@ -1,8 +1,7 @@ #![cfg(unix)] use killport::cli::Mode; -use killport::docker::DockerContainer; -use killport::killport::{Killable, KillableType, KillportOperations}; +use killport::killport::{Killable, KillableType}; use killport::signal::KillportSignal; use killport::unix::UnixProcess; use mockall::*; From de561b5942e17063ff3df89fb0e7abd063799200 Mon Sep 17 00:00:00 2001 From: Francisco Jimenez Cabrera Date: Fri, 31 May 2024 19:16:07 +0100 Subject: [PATCH 2/2] Use different ports --- Cargo.lock | 2 +- tests/integration_test.rs | 42 +++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6edffcb..7a2553a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -753,7 +753,7 @@ dependencies = [ [[package]] name = "killport" -version = "1.0.0" +version = "1.1.0" dependencies = [ "assert_cmd", "bollard", diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 5a011d0..d6d7382 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -33,10 +33,10 @@ fn test_basic_kill_no_process() { fn test_basic_kill_process() { let tempdir = tempdir().unwrap(); let tempdir_path = tempdir.path(); - let mut child = start_listener_process(tempdir_path, 8081); + let mut child = start_listener_process(tempdir_path, 8180); let mut cmd = Command::cargo_bin("killport").unwrap(); - let command = cmd.args(&["8081"]).assert().success(); - assert_match(&command.get_output().stdout, "Successfully killed", 8081); + let command = cmd.args(&["8180"]).assert().success(); + assert_match(&command.get_output().stdout, "Successfully killed", 8180); // Clean up let _ = child.kill(); let _ = child.wait(); @@ -49,10 +49,10 @@ fn test_signal_handling() { let tempdir_path = tempdir.path(); for signal in ["sighup", "sigint", "sigkill"].iter() { - let mut child = start_listener_process(tempdir_path, 8082); + let mut child = start_listener_process(tempdir_path, 8280); let mut cmd = Command::cargo_bin("killport").unwrap(); - let command = cmd.args(&["8082", "-s", signal]).assert().success(); - assert_match(&command.get_output().stdout, "Successfully killed", 8082); + let command = cmd.args(&["8280", "-s", signal]).assert().success(); + assert_match(&command.get_output().stdout, "Successfully killed", 8280); // Clean up let _ = child.kill(); let _ = child.wait(); @@ -65,33 +65,37 @@ fn test_mode_option() { let tempdir = tempdir().unwrap(); let tempdir_path = tempdir.path(); - for mode in ["auto", "process"].iter() { - let mut child = start_listener_process(tempdir_path, 8083); + for (i, mode) in ["auto", "process"].iter().enumerate() { + let port = 8380 + i as u16; + let mut child = start_listener_process(tempdir_path, port); let mut cmd = Command::cargo_bin("killport").unwrap(); - let command = cmd.args(&["8083", "--mode", mode]).assert().success(); - assert_match(&command.get_output().stdout, "Successfully killed", 8083); + let command = cmd + .args(&[&port.to_string(), "--mode", mode]) + .assert() + .success(); + assert_match(&command.get_output().stdout, "Successfully killed", port); // Clean up let _ = child.kill(); let _ = child.wait(); } let mut cmd = Command::cargo_bin("killport").unwrap(); - cmd.args(&["8083", "--mode", "auto"]) + cmd.args(&["8383", "--mode", "auto"]) .assert() .success() - .stdout(format!("No service found using port 8083\n")); + .stdout(format!("No service found using port 8383\n")); let mut cmd = Command::cargo_bin("killport").unwrap(); - cmd.args(&["8083", "--mode", "process"]) + cmd.args(&["8383", "--mode", "process"]) .assert() .success() - .stdout(format!("No process found using port 8083\n")); + .stdout(format!("No process found using port 8383\n")); let mut cmd = Command::cargo_bin("killport").unwrap(); - cmd.args(&["8083", "--mode", "container"]) + cmd.args(&["8383", "--mode", "container"]) .assert() .success() - .stdout(format!("No container found using port 8083\n")); + .stdout(format!("No container found using port 8383\n")); } /// Tests the `--dry-run` option to ensure no actual killing of the process. @@ -99,11 +103,11 @@ fn test_mode_option() { fn test_dry_run_option() { let tempdir = tempdir().unwrap(); let tempdir_path = tempdir.path(); - let mut child = start_listener_process(tempdir_path, 8084); + let mut child = start_listener_process(tempdir_path, 8480); let mut cmd = Command::cargo_bin("killport").unwrap(); - let command = cmd.args(&["8084", "--dry-run"]).assert().success(); - assert_match(&command.get_output().stdout, "Would kill", 8084); + let command = cmd.args(&["8480", "--dry-run"]).assert().success(); + assert_match(&command.get_output().stdout, "Would kill", 8480); // Clean up let _ = child.kill(); let _ = child.wait();