2019-10-09 09:25:02 -04:00
|
|
|
"""Test yadm.alt-copy"""
|
|
|
|
|
|
|
|
import os
|
2023-07-10 10:14:33 -04:00
|
|
|
|
2019-10-09 09:25:02 -04:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-10 15:43:17 -04:00
|
|
|
"setting, expect_link, pre_existing",
|
|
|
|
[
|
2019-10-09 09:25:02 -04:00
|
|
|
(None, True, None),
|
|
|
|
(True, False, None),
|
|
|
|
(False, True, None),
|
2023-07-10 15:43:17 -04:00
|
|
|
(True, False, "link"),
|
|
|
|
(True, False, "file"),
|
2019-10-09 09:25:02 -04:00
|
|
|
],
|
|
|
|
ids=[
|
2023-07-10 15:43:17 -04:00
|
|
|
"unset",
|
|
|
|
"true",
|
|
|
|
"false",
|
|
|
|
"pre-existing symlink",
|
|
|
|
"pre-existing file",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
@pytest.mark.usefixtures("ds1_copy")
|
|
|
|
def test_alt_copy(runner, yadm_cmd, paths, tst_sys, setting, expect_link, pre_existing):
|
2019-10-09 09:25:02 -04:00
|
|
|
"""Test yadm.alt-copy"""
|
|
|
|
|
|
|
|
if setting is not None:
|
2023-07-10 15:43:17 -04:00
|
|
|
os.system(" ".join(yadm_cmd("config", "yadm.alt-copy", str(setting))))
|
2019-10-09 09:25:02 -04:00
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
expected_content = f"test_alt_copy##os.{tst_sys}"
|
2019-10-09 09:25:02 -04:00
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
alt_path = paths.work.join("test_alt_copy")
|
|
|
|
if pre_existing == "symlink":
|
2019-10-09 09:25:02 -04:00
|
|
|
alt_path.mklinkto(expected_content)
|
2023-07-10 15:43:17 -04:00
|
|
|
elif pre_existing == "file":
|
|
|
|
alt_path.write("wrong content")
|
2019-10-09 09:25:02 -04:00
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(yadm_cmd("alt"))
|
2019-10-09 09:25:02 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
2024-11-28 17:28:32 -05:00
|
|
|
action = "Copying" if setting is True else "Linking"
|
|
|
|
assert action in run.out
|
2019-10-09 09:25:02 -04:00
|
|
|
|
|
|
|
assert alt_path.read() == expected_content
|
|
|
|
assert alt_path.islink() == expect_link
|