nixos-rebuild-ng: move test to the correct file

This commit is contained in:
Thiago Kenji Okada 2024-11-26 09:37:47 +00:00
parent 4adad7f664
commit 10f2b080c3
3 changed files with 36 additions and 35 deletions

View File

@ -13,7 +13,7 @@ def dict_to_flags(d: dict[str, Args]) -> list[str]:
flag = f"--{'-'.join(key.split('_'))}"
match value:
case None | False | 0 | []:
pass
continue
case True:
flags.append(flag)
case int():

View File

@ -111,37 +111,3 @@ def test_profile_from_name(mock_mkdir: Any) -> None:
Path("/nix/var/nix/profiles/system-profiles/something"),
)
mock_mkdir.assert_called_once()
def test_remote_from_name(monkeypatch: Any, tmpdir: Path) -> None:
monkeypatch.setenv("NIX_SSHOPTS", "")
assert m.Remote.from_arg("user@localhost", None, tmpdir) == m.Remote(
"user@localhost",
[
"-o",
"ControlMaster=auto",
"-o",
f"ControlPath={tmpdir / "ssh-%n"}",
"-o",
"ControlPersist=60",
],
False,
)
monkeypatch.setenv("NIX_SSHOPTS", "-f foo -b bar")
assert m.Remote.from_arg("user@localhost", True, tmpdir) == m.Remote(
"user@localhost",
[
"-f",
"foo",
"-b",
"bar",
"-o",
"ControlMaster=auto",
"-o",
f"ControlPath={tmpdir / "ssh-%n"}",
"-o",
"ControlPersist=60",
],
True,
)

View File

@ -1,3 +1,4 @@
from pathlib import Path
from typing import Any
from unittest.mock import patch
@ -87,3 +88,37 @@ def test_run(mock_run: Any) -> None:
remote=m.Remote("user@localhost", [], False),
capture_output=True,
)
def test_remote_from_name(monkeypatch: Any, tmpdir: Path) -> None:
monkeypatch.setenv("NIX_SSHOPTS", "")
assert m.Remote.from_arg("user@localhost", None, tmpdir) == m.Remote(
"user@localhost",
opts=[
"-o",
"ControlMaster=auto",
"-o",
f"ControlPath={tmpdir / "ssh-%n"}",
"-o",
"ControlPersist=60",
],
tty=False,
)
monkeypatch.setenv("NIX_SSHOPTS", "-f foo -b bar")
assert m.Remote.from_arg("user@localhost", True, tmpdir) == m.Remote(
"user@localhost",
opts=[
"-f",
"foo",
"-b",
"bar",
"-o",
"ControlMaster=auto",
"-o",
f"ControlPath={tmpdir / "ssh-%n"}",
"-o",
"ControlPersist=60",
],
tty=True,
)