Skip to content

Commit

Permalink
fix binary_archiver tests for modern exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Jul 19, 2024
1 parent edfca29 commit 7aabe82
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/borg/testsuite/archiver/config_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def test_config(archivers, request):

cmd(archiver, "config", "--list", "--delete", exit_code=2)
if archiver.FORK_DEFAULT:
cmd(archiver, "config", exit_code=2)
expected_ec = CommandError().exit_code
cmd(archiver, "config", exit_code=expected_ec)
else:
with pytest.raises(CommandError):
cmd(archiver, "config")
Expand Down
10 changes: 8 additions & 2 deletions src/borg/testsuite/archiver/create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ def test_create_content_from_command_with_failed_command(archivers, request):
archiver = request.getfixturevalue(archivers)
cmd(archiver, "rcreate", RK_ENCRYPTION)
if archiver.FORK_DEFAULT:
output = cmd(archiver, "create", "--content-from-command", "test", "--", "sh", "-c", "exit 73;", exit_code=2)
expected_ec = CommandError().exit_code
output = cmd(
archiver, "create", "--content-from-command", "test", "--", "sh", "-c", "exit 73;", exit_code=expected_ec
)
assert output.endswith("Command 'sh' exited with status 73" + os.linesep)
else:
with pytest.raises(CommandError):
Expand Down Expand Up @@ -418,7 +421,10 @@ def test_create_paths_from_command_with_failed_command(archivers, request):
archiver = request.getfixturevalue(archivers)
cmd(archiver, "rcreate", RK_ENCRYPTION)
if archiver.FORK_DEFAULT:
output = cmd(archiver, "create", "--paths-from-command", "test", "--", "sh", "-c", "exit 73;", exit_code=2)
expected_ec = CommandError().exit_code
output = cmd(
archiver, "create", "--paths-from-command", "test", "--", "sh", "-c", "exit 73;", exit_code=expected_ec
)
assert output.endswith("Command 'sh' exited with status 73" + os.linesep)
else:
with pytest.raises(CommandError):
Expand Down
17 changes: 11 additions & 6 deletions src/borg/testsuite/archiver/key_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ...constants import * # NOQA
from ...crypto.key import AESOCBRepoKey, AESOCBKeyfileKey, CHPOKeyfileKey, Passphrase
from ...crypto.keymanager import RepoIdMismatch, NotABorgKeyFile
from ...helpers import EXIT_ERROR, CommandError
from ...helpers import CommandError
from ...helpers import bin_to_hex, hex_to_bin
from ...helpers import msgpack
from ...repository import Repository
Expand Down Expand Up @@ -171,7 +171,8 @@ def test_key_export_directory(archivers, request):
os.mkdir(export_directory)
cmd(archiver, "rcreate", RK_ENCRYPTION)
if archiver.FORK_DEFAULT:
cmd(archiver, "key", "export", export_directory, exit_code=EXIT_ERROR)
expected_ec = CommandError().exit_code
cmd(archiver, "key", "export", export_directory, exit_code=expected_ec)
else:
with pytest.raises(CommandError):
cmd(archiver, "key", "export", export_directory)
Expand All @@ -183,7 +184,8 @@ def test_key_export_qr_directory(archivers, request):
os.mkdir(export_directory)
cmd(archiver, "rcreate", RK_ENCRYPTION)
if archiver.FORK_DEFAULT:
cmd(archiver, "key", "export", "--qr-html", export_directory, exit_code=EXIT_ERROR)
expected_ec = CommandError().exit_code
cmd(archiver, "key", "export", "--qr-html", export_directory, exit_code=expected_ec)
else:
with pytest.raises(CommandError):
cmd(archiver, "key", "export", "--qr-html", export_directory)
Expand All @@ -194,7 +196,8 @@ def test_key_import_errors(archivers, request):
export_file = archiver.output_path + "/exported"
cmd(archiver, "rcreate", KF_ENCRYPTION)
if archiver.FORK_DEFAULT:
cmd(archiver, "key", "import", export_file, exit_code=EXIT_ERROR)
expected_ec = CommandError().exit_code
cmd(archiver, "key", "import", export_file, exit_code=expected_ec)
else:
with pytest.raises(CommandError):
cmd(archiver, "key", "import", export_file)
Expand All @@ -203,7 +206,8 @@ def test_key_import_errors(archivers, request):
fd.write("something not a key\n")

if archiver.FORK_DEFAULT:
cmd(archiver, "key", "import", export_file, exit_code=2)
expected_ec = NotABorgKeyFile().exit_code
cmd(archiver, "key", "import", export_file, exit_code=expected_ec)
else:
with pytest.raises(NotABorgKeyFile):
cmd(archiver, "key", "import", export_file)
Expand All @@ -212,7 +216,8 @@ def test_key_import_errors(archivers, request):
fd.write("BORG_KEY a0a0a0\n")

if archiver.FORK_DEFAULT:
cmd(archiver, "key", "import", export_file, exit_code=2)
expected_ec = RepoIdMismatch().exit_code
cmd(archiver, "key", "import", export_file, exit_code=expected_ec)
else:
with pytest.raises(RepoIdMismatch):
cmd(archiver, "key", "import", export_file)
Expand Down
3 changes: 2 additions & 1 deletion src/borg/testsuite/archiver/rcreate_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def test_rcreate_nested_repositories(archivers, request):
cmd(archiver, "rcreate", RK_ENCRYPTION)
archiver.repository_location += "/nested"
if archiver.FORK_DEFAULT:
cmd(archiver, "rcreate", RK_ENCRYPTION, exit_code=2)
expected_ec = Repository.AlreadyExists().exit_code
cmd(archiver, "rcreate", RK_ENCRYPTION, exit_code=expected_ec)
else:
with pytest.raises(Repository.AlreadyExists):
cmd(archiver, "rcreate", RK_ENCRYPTION)
Expand Down
3 changes: 2 additions & 1 deletion src/borg/testsuite/archiver/rdelete_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def test_delete_repo(archivers, request):
cmd(archiver, "create", "test.2", "input")
os.environ["BORG_DELETE_I_KNOW_WHAT_I_AM_DOING"] = "no"
if archiver.FORK_DEFAULT:
cmd(archiver, "rdelete", exit_code=2)
expected_ec = CancelledByUser().exit_code
cmd(archiver, "rdelete", exit_code=expected_ec)
else:
with pytest.raises(CancelledByUser):
cmd(archiver, "rdelete")
Expand Down
3 changes: 2 additions & 1 deletion src/borg/testsuite/archiver/recreate_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def test_recreate_target_rc(archivers, request):
archiver = request.getfixturevalue(archivers)
cmd(archiver, "rcreate", RK_ENCRYPTION)
if archiver.FORK_DEFAULT:
output = cmd(archiver, "recreate", "--target=asdf", exit_code=2)
expected_ec = CommandError().exit_code
output = cmd(archiver, "recreate", "--target=asdf", exit_code=expected_ec)
assert "Need to specify single archive" in output
else:
with pytest.raises(CommandError):
Expand Down

0 comments on commit 7aabe82

Please sign in to comment.