test: acme --log flag asserts explicit log file path
This commit is contained in:
+8
-3
@@ -61,14 +61,19 @@ class TestRunAcme:
|
|||||||
@patch("lib.acme._find_acme")
|
@patch("lib.acme._find_acme")
|
||||||
@patch("lib.acme.subprocess.run")
|
@patch("lib.acme.subprocess.run")
|
||||||
def test_log_flag_is_last(self, mock_run, mock_find):
|
def test_log_flag_is_last(self, mock_run, mock_find):
|
||||||
# --log must trail the subcommand args: acme.sh would otherwise
|
# --log <file> must trail the subcommand args: acme.sh would
|
||||||
# consume the first subcommand arg as its (optional) file argument.
|
# otherwise consume the first subcommand arg as its file argument.
|
||||||
|
# The explicit file path (not a bare trailing --log) is required
|
||||||
|
# because a valueless trailing --log makes acme.sh's arg loop
|
||||||
|
# double-shift under dash and fail with "shift: can't shift that
|
||||||
|
# many".
|
||||||
mock_find.return_value = "/usr/local/bin/acme.sh"
|
mock_find.return_value = "/usr/local/bin/acme.sh"
|
||||||
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
|
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
|
||||||
acme._run_acme(["--issue", "-d", "example.com"])
|
acme._run_acme(["--issue", "-d", "example.com"])
|
||||||
cmd = mock_run.call_args[0][0]
|
cmd = mock_run.call_args[0][0]
|
||||||
assert cmd.count("--log") == 1
|
assert cmd.count("--log") == 1
|
||||||
assert cmd[-1] == "--log"
|
assert cmd[-2] == "--log"
|
||||||
|
assert cmd[-1].endswith("acme.sh.log")
|
||||||
assert cmd.index("--issue") < cmd.index("--log")
|
assert cmd.index("--issue") < cmd.index("--log")
|
||||||
assert "example.com" in cmd
|
assert "example.com" in cmd
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user