Skip to content

Commit 5e34add

Browse files
committed
nixos-rebuild-ng: mock test correctly
1 parent 40f8433 commit 5e34add

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,14 +586,49 @@ def test_execute_switch_rollback(mock_run: Any, tmp_path: Path) -> None:
586586
nixpkgs_path = tmp_path / "nixpkgs"
587587
nixpkgs_path.touch()
588588

589+
def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
590+
if args[0] == "nix-instantiate":
591+
return CompletedProcess([], 0, str(nixpkgs_path))
592+
elif args[0] == "git":
593+
return CompletedProcess([], 0, "")
594+
else:
595+
return CompletedProcess([], 0)
596+
597+
mock_run.side_effect = run_side_effect
598+
589599
nr.execute(
590-
["nixos-rebuild", "switch", "--rollback", "--install-bootloader", "--no-reexec"]
600+
[
601+
"nixos-rebuild",
602+
"switch",
603+
"--rollback",
604+
"--install-bootloader",
605+
"--no-reexec",
606+
"--no-flake",
607+
]
591608
)
592609

593-
assert mock_run.call_count >= 2
594-
# ignoring update_nixpkgs_rev calls
610+
assert mock_run.call_count == 4
595611
mock_run.assert_has_calls(
596612
[
613+
call(
614+
["nix-instantiate", "--find-file", "nixpkgs"],
615+
check=False,
616+
stdout=PIPE,
617+
**DEFAULT_RUN_KWARGS,
618+
),
619+
call(
620+
[
621+
"git",
622+
"-C",
623+
nixpkgs_path,
624+
"rev-parse",
625+
"--short",
626+
"HEAD",
627+
],
628+
check=False,
629+
capture_output=True,
630+
**DEFAULT_RUN_KWARGS,
631+
),
597632
call(
598633
[
599634
"nix-env",

0 commit comments

Comments
 (0)