From 595a445f4d1576ca7bf1623d71357affbbf6e97d Mon Sep 17 00:00:00 2001 From: c-c-k Date: Fri, 28 Jul 2023 20:05:20 +0300 Subject: [PATCH] Add: test_link_relink_aborts_on_failed_backup --- tests/test_link.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_link.py b/tests/test_link.py index 90aa705..db55f5f 100644 --- a/tests/test_link.py +++ b/tests/test_link.py @@ -1037,6 +1037,26 @@ def test_link_relink_backups_symlink(home, dotfiles, run_dotbot): assert file.read() == "apple" +def test_link_relink_aborts_on_failed_backup(home, dotfiles, run_dotbot): + """Verify relink is aborted if backup fails.""" + + dotfiles.write("f", "apple") + with open(os.path.join(home, "f"), "w") as file: + file.write("grape") + os.symlink(os.path.join(home, "f"), os.path.join(home, ".f")) + dotfiles.write("backup") + + backup_root = os.path.join(dotfiles.directory, "backup") + dotfiles.write_config( + [{"link": {"~/.f": {"path": "f", "relink": True, "backup-root": backup_root}}}] + ) + with pytest.raises(SystemExit): + run_dotbot() + + with open(os.path.join(home, ".f"), "r") as file: + assert file.read() == "grape" + + def test_link_relink_relative_leaves_file(home, dotfiles, run_dotbot): """Verify relink relative does not incorrectly relink file."""