Skip to content

Commit

Permalink
Merge pull request #42 from jkfran/v1.1.0
Browse files Browse the repository at this point in the history
Fix tests and release v1.1.0
  • Loading branch information
jkfran committed May 31, 2024
2 parents 55d9978 + de561b5 commit ebd2c26
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 26 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,4 +25,4 @@ jobs:
override: true

- name: Run tests
run: cargo test --all
run: cargo test --tests -- --test-threads=1
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "killport"
version = "1.0.0"
version = "1.1.0"
authors = ["Francisco Jimenez Cabrera <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
42 changes: 23 additions & 19 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -65,45 +65,49 @@ 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.
#[test]
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();
Expand Down
3 changes: 1 addition & 2 deletions tests/killport_unix_tests.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down

0 comments on commit ebd2c26

Please sign in to comment.