From c6e9bd02ca1197289185ef9df5fc9b295352965f Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 3 Dec 2024 12:54:13 +0000 Subject: [PATCH] nixos-rebuild-ng: add test to `nixos-rebuild build` --- .../nixos-rebuild-ng/src/tests/test_main.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py index 9337fda44dc0..913103985f66 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py @@ -445,6 +445,35 @@ def test_execute_switch_rollback(mock_run: Any, tmp_path: Path) -> None: ) +@patch(get_qualified_name(nr.process.subprocess.run), autospec=True) +def test_execute_build(mock_run: Any, tmp_path: Path) -> None: + config_path = tmp_path / "test" + config_path.touch() + mock_run.side_effect = [ + # nixos_build_flake + CompletedProcess([], 0, str(config_path)), + ] + + nr.execute(["nixos-rebuild", "build", "--no-flake", "--fast"]) + + assert mock_run.call_count == 1 + mock_run.assert_has_calls( + [ + call( + [ + "nix-build", + "", + "--attr", + "config.system.build.toplevel", + ], + check=True, + stdout=PIPE, + **DEFAULT_RUN_KWARGS, + ) + ] + ) + + @patch(get_qualified_name(nr.process.subprocess.run), autospec=True) @patch(get_qualified_name(nr.nix.Path.exists, nr.nix), autospec=True, return_value=True) @patch(get_qualified_name(nr.nix.Path.mkdir, nr.nix), autospec=True)