nixos-rebuild-ng: fix cleanup_ssh
This commit is contained in:
@@ -69,7 +69,9 @@ class RunKwargs(TypedDict, total=False):
|
||||
def cleanup_ssh(tmp_dir: Path) -> None:
|
||||
"Close SSH ControlMaster connection."
|
||||
for ctrl in tmp_dir.glob("ssh-*"):
|
||||
subprocess.run(["ssh", "-o", f"ControlPath={ctrl}", "exit"], check=False)
|
||||
subprocess.run(
|
||||
["ssh", "-o", f"ControlPath={ctrl}", "-O", "exit", "dummyhost"], check=False
|
||||
)
|
||||
|
||||
|
||||
def run_wrapper(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import call, patch
|
||||
|
||||
import nixos_rebuild.models as m
|
||||
import nixos_rebuild.process as p
|
||||
@@ -8,6 +8,28 @@ import nixos_rebuild.process as p
|
||||
from .helpers import get_qualified_name
|
||||
|
||||
|
||||
@patch(get_qualified_name(p.subprocess.run))
|
||||
def test_cleanup_ssh(mock_run: Any, tmp_path: Path) -> None:
|
||||
(tmp_path / "ssh-conn").touch()
|
||||
|
||||
p.cleanup_ssh(tmp_path)
|
||||
mock_run.assert_has_calls(
|
||||
[
|
||||
call(
|
||||
[
|
||||
"ssh",
|
||||
"-o",
|
||||
f"ControlPath={tmp_path}/ssh-conn",
|
||||
"-O",
|
||||
"exit",
|
||||
"dummyhost",
|
||||
],
|
||||
check=False,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@patch(get_qualified_name(p.subprocess.run))
|
||||
def test_run(mock_run: Any) -> None:
|
||||
p.run_wrapper(["test", "--with", "flags"], check=True)
|
||||
|
||||
Reference in New Issue
Block a user