2019-10-15 08:17:38 -04:00
|
|
|
"""Unit tests: exclude_encrypted"""
|
2024-11-11 16:30:41 -05:00
|
|
|
|
2019-10-15 08:17:38 -04:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
@pytest.mark.parametrize("exclude", ["missing", "outdated", "up-to-date"])
|
|
|
|
@pytest.mark.parametrize("encrypt_exists", [True, False], ids=["encrypt", "no-encrypt"])
|
|
|
|
@pytest.mark.parametrize("auto_exclude", [True, False], ids=["enabled", "disabled"])
|
|
|
|
def test_exclude_encrypted(runner, tmpdir, yadm, encrypt_exists, auto_exclude, exclude):
|
2019-10-15 08:17:38 -04:00
|
|
|
"""Test exclude_encrypted()"""
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
header = "# yadm-auto-excludes\n# This section is managed by yadm.\n# Any edits below will be lost.\n"
|
2019-10-15 08:17:38 -04:00
|
|
|
|
|
|
|
config_function = 'function config() { echo "false";}'
|
|
|
|
if auto_exclude:
|
2023-07-10 15:43:17 -04:00
|
|
|
config_function = "function config() { return; }"
|
2019-10-15 08:17:38 -04:00
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
encrypt_file = tmpdir.join("encrypt_file")
|
|
|
|
repo_dir = tmpdir.join("repodir")
|
|
|
|
exclude_file = repo_dir.join("info/exclude")
|
2019-10-15 08:17:38 -04:00
|
|
|
|
|
|
|
if encrypt_exists:
|
2023-07-10 15:43:17 -04:00
|
|
|
encrypt_file.write("test-encrypt-data\n", ensure=True)
|
|
|
|
if exclude == "outdated":
|
|
|
|
exclude_file.write(f"original-exclude\n{header}outdated\n", ensure=True)
|
|
|
|
elif exclude == "up-to-date":
|
|
|
|
exclude_file.write(f"original-exclude\n{header}test-encrypt-data\n", ensure=True)
|
2019-10-15 08:17:38 -04:00
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
{config_function}
|
|
|
|
DEBUG=1
|
|
|
|
YADM_ENCRYPT="{encrypt_file}"
|
|
|
|
YADM_REPO="{repo_dir}"
|
|
|
|
exclude_encrypted
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-10-15 08:17:38 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
2019-10-15 08:17:38 -04:00
|
|
|
|
|
|
|
if auto_exclude:
|
|
|
|
if encrypt_exists:
|
|
|
|
assert exclude_file.exists()
|
2023-07-10 15:43:17 -04:00
|
|
|
if exclude == "missing":
|
|
|
|
assert exclude_file.read() == f"{header}test-encrypt-data\n"
|
2019-10-15 08:17:38 -04:00
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert exclude_file.read() == ("original-exclude\n" f"{header}test-encrypt-data\n")
|
|
|
|
if exclude != "up-to-date":
|
|
|
|
assert f"Updating {exclude_file}" in run.out
|
2019-10-15 08:17:38 -04:00
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.out == ""
|
2019-10-15 08:17:38 -04:00
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.out == ""
|
2019-10-15 08:17:38 -04:00
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.out == ""
|