Skip to content

Commit

Permalink
Use different ports
Browse files Browse the repository at this point in the history
  • Loading branch information
jkfran committed May 31, 2024
1 parent 036b319 commit de561b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
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.

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

0 comments on commit de561b5

Please sign in to comment.