nixos-rebuild-ng: improve test for test_remote_build
This commit is contained in:
@@ -83,9 +83,7 @@ def test_execute_nix_boot(mock_run: Any, tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "test"
|
||||
config_path.touch()
|
||||
|
||||
def run_wrapper_side_effect(
|
||||
args: list[str], **kwargs: Any
|
||||
) -> CompletedProcess[str]:
|
||||
def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
|
||||
if args[0] == "nix-instantiate":
|
||||
return CompletedProcess([], 0, str(nixpkgs_path))
|
||||
elif args[0] == "git" and "rev-parse" in args:
|
||||
@@ -95,7 +93,7 @@ def test_execute_nix_boot(mock_run: Any, tmp_path: Path) -> None:
|
||||
else:
|
||||
return CompletedProcess([], 0)
|
||||
|
||||
mock_run.side_effect = run_wrapper_side_effect
|
||||
mock_run.side_effect = run_side_effect
|
||||
|
||||
nr.execute(["nixos-rebuild", "boot", "--no-flake", "-vvv", "--fast"])
|
||||
|
||||
@@ -158,15 +156,13 @@ def test_execute_nix_switch_flake(mock_run: Any, tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "test"
|
||||
config_path.touch()
|
||||
|
||||
def run_wrapper_side_effect(
|
||||
args: list[str], **kwargs: Any
|
||||
) -> CompletedProcess[str]:
|
||||
def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
|
||||
if args[0] == "nix":
|
||||
return CompletedProcess([], 0, str(config_path))
|
||||
else:
|
||||
return CompletedProcess([], 0)
|
||||
|
||||
mock_run.side_effect = run_wrapper_side_effect
|
||||
mock_run.side_effect = run_side_effect
|
||||
|
||||
nr.execute(
|
||||
[
|
||||
@@ -231,15 +227,13 @@ def test_execute_nix_switch_flake_target_host(
|
||||
config_path = tmp_path / "test"
|
||||
config_path.touch()
|
||||
|
||||
def run_wrapper_side_effect(
|
||||
args: list[str], **kwargs: Any
|
||||
) -> CompletedProcess[str]:
|
||||
def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
|
||||
if args[0] == "nix":
|
||||
return CompletedProcess([], 0, str(config_path))
|
||||
else:
|
||||
return CompletedProcess([], 0)
|
||||
|
||||
mock_run.side_effect = run_wrapper_side_effect
|
||||
mock_run.side_effect = run_side_effect
|
||||
|
||||
nr.execute(
|
||||
[
|
||||
@@ -322,9 +316,7 @@ def test_execute_nix_switch_flake_build_host(
|
||||
config_path = tmp_path / "test"
|
||||
config_path.touch()
|
||||
|
||||
def run_wrapper_side_effect(
|
||||
args: list[str], **kwargs: Any
|
||||
) -> CompletedProcess[str]:
|
||||
def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
|
||||
if args[0] == "nix" and "eval" in args:
|
||||
return CompletedProcess([], 0, str(config_path))
|
||||
if args[0] == "ssh" and "nix" in args:
|
||||
@@ -332,7 +324,7 @@ def test_execute_nix_switch_flake_build_host(
|
||||
else:
|
||||
return CompletedProcess([], 0)
|
||||
|
||||
mock_run.side_effect = run_wrapper_side_effect
|
||||
mock_run.side_effect = run_side_effect
|
||||
|
||||
nr.execute(
|
||||
[
|
||||
@@ -483,15 +475,13 @@ def test_execute_test_flake(mock_run: Any, tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "test"
|
||||
config_path.touch()
|
||||
|
||||
def run_wrapper_side_effect(
|
||||
args: list[str], **kwargs: Any
|
||||
) -> CompletedProcess[str]:
|
||||
def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
|
||||
if args[0] == "nix":
|
||||
return CompletedProcess([], 0, str(config_path))
|
||||
else:
|
||||
return CompletedProcess([], 0)
|
||||
|
||||
mock_run.side_effect = run_wrapper_side_effect
|
||||
mock_run.side_effect = run_side_effect
|
||||
|
||||
nr.execute(
|
||||
["nixos-rebuild", "test", "--flake", "github:user/repo#hostname", "--fast"]
|
||||
@@ -530,9 +520,7 @@ def test_execute_test_rollback(
|
||||
mock_path_exists: Any,
|
||||
mock_run: Any,
|
||||
) -> None:
|
||||
def run_wrapper_side_effect(
|
||||
args: list[str], **kwargs: Any
|
||||
) -> CompletedProcess[str]:
|
||||
def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
|
||||
if args[0] == "nix-env":
|
||||
return CompletedProcess(
|
||||
[],
|
||||
@@ -546,7 +534,7 @@ def test_execute_test_rollback(
|
||||
else:
|
||||
return CompletedProcess([], 0)
|
||||
|
||||
mock_run.side_effect = run_wrapper_side_effect
|
||||
mock_run.side_effect = run_side_effect
|
||||
|
||||
nr.execute(
|
||||
["nixos-rebuild", "test", "--rollback", "--profile-name", "foo", "--fast"]
|
||||
|
||||
@@ -88,16 +88,14 @@ def test_remote_build(mock_uuid4: Any, mock_run: Any, monkeypatch: Any) -> None:
|
||||
elif args[0] == "mktemp":
|
||||
return CompletedProcess([], 0, stdout=" \n/tmp/tmpdir\n ")
|
||||
elif args[0] == "nix-store":
|
||||
return CompletedProcess(
|
||||
[], 0, stdout=" \n/tmp/tmpdir/00000000000000000000000000000000\n "
|
||||
)
|
||||
return CompletedProcess([], 0, stdout=" \n/tmp/tmpdir/config\n ")
|
||||
elif args[0] == "readlink":
|
||||
return CompletedProcess([], 0, stdout=" \n/path/to/config\n ")
|
||||
else:
|
||||
return CompletedProcess([], 0)
|
||||
|
||||
mock_run.side_effect = run_wrapper_side_effect
|
||||
mock_uuid4.return_value = uuid.UUID(int=0)
|
||||
mock_uuid4.side_effect = [uuid.UUID(int=1), uuid.UUID(int=2)]
|
||||
|
||||
assert n.remote_build(
|
||||
"config.system.build.toplevel",
|
||||
@@ -117,7 +115,7 @@ def test_remote_build(mock_uuid4: Any, mock_run: Any, monkeypatch: Any) -> None:
|
||||
"--attr",
|
||||
"preAttr.config.system.build.toplevel",
|
||||
"--add-root",
|
||||
n.tmpdir.TMPDIR_PATH / "00000000000000000000000000000000",
|
||||
n.tmpdir.TMPDIR_PATH / "00000000000000000000000000000001",
|
||||
"--inst",
|
||||
],
|
||||
stdout=PIPE,
|
||||
@@ -145,14 +143,14 @@ def test_remote_build(mock_uuid4: Any, mock_run: Any, monkeypatch: Any) -> None:
|
||||
"--realise",
|
||||
Path("/path/to/file"),
|
||||
"--add-root",
|
||||
Path("/tmp/tmpdir/00000000000000000000000000000000"),
|
||||
Path("/tmp/tmpdir/00000000000000000000000000000002"),
|
||||
"--build",
|
||||
],
|
||||
remote=build_host,
|
||||
stdout=PIPE,
|
||||
),
|
||||
call(
|
||||
["readlink", "-f", "/tmp/tmpdir/00000000000000000000000000000000"],
|
||||
["readlink", "-f", "/tmp/tmpdir/config"],
|
||||
remote=build_host,
|
||||
stdout=PIPE,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user