generate_test_vars: add test
This commit is contained in:
@@ -206,13 +206,13 @@ def parse_args() -> Options:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def generate_test_vars(
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
clean: bool,
|
||||||
os.environ["CLAN_NO_COMMIT"] = "1"
|
repo_root: Path,
|
||||||
opts = parse_args()
|
test_dir: Path,
|
||||||
test_dir = opts.test_dir
|
check_attr: str,
|
||||||
|
) -> None:
|
||||||
if opts.clean:
|
if clean:
|
||||||
shutil.rmtree(test_dir / "vars", ignore_errors=True)
|
shutil.rmtree(test_dir / "vars", ignore_errors=True)
|
||||||
shutil.rmtree(test_dir / "sops", ignore_errors=True)
|
shutil.rmtree(test_dir / "sops", ignore_errors=True)
|
||||||
|
|
||||||
@@ -222,10 +222,10 @@ def main() -> None:
|
|||||||
if system.endswith("-darwin"):
|
if system.endswith("-darwin"):
|
||||||
test_system = system.rstrip("darwin") + "linux"
|
test_system = system.rstrip("darwin") + "linux"
|
||||||
|
|
||||||
flake = TestFlake(opts.check_attr, test_dir, str(opts.repo_root))
|
flake = TestFlake(check_attr, test_dir, str(repo_root))
|
||||||
machine_names = get_machine_names(
|
machine_names = get_machine_names(
|
||||||
opts.repo_root,
|
repo_root,
|
||||||
opts.check_attr,
|
check_attr,
|
||||||
test_system,
|
test_system,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -233,16 +233,16 @@ def main() -> None:
|
|||||||
|
|
||||||
flake.precache(
|
flake.precache(
|
||||||
[
|
[
|
||||||
f"checks.{test_system}.{opts.check_attr}.machinesCross.{system}.{{{','.join(machine_names)}}}.config.clan.core.vars.generators.*.validationHash",
|
f"checks.{test_system}.{check_attr}.machinesCross.{system}.{{{','.join(machine_names)}}}.config.clan.core.vars.generators.*.validationHash",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# This hack is necessary because the sops store uses flake.path to find the machine keys
|
# This hack is necessary because the sops store uses flake.path to find the machine keys
|
||||||
# This hack does not work because flake.invalidate_cache resets _path
|
# This hack does not work because flake.invalidate_cache resets _path
|
||||||
flake._path = opts.test_dir # noqa: SLF001
|
flake._path = test_dir # noqa: SLF001
|
||||||
|
|
||||||
machines = [
|
machines = [
|
||||||
TestMachine(name, flake, test_dir, opts.check_attr) for name in machine_names
|
TestMachine(name, flake, test_dir, check_attr) for name in machine_names
|
||||||
]
|
]
|
||||||
user = "admin"
|
user = "admin"
|
||||||
admin_key_path = Path(test_dir.resolve() / "sops" / "users" / user / "key.json")
|
admin_key_path = Path(test_dir.resolve() / "sops" / "users" / user / "key.json")
|
||||||
@@ -287,5 +287,17 @@ def main() -> None:
|
|||||||
run_generators(list(machines), prompt_values=mocked_prompts)
|
run_generators(list(machines), prompt_values=mocked_prompts)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
os.environ["CLAN_NO_COMMIT"] = "1"
|
||||||
|
args = parse_args()
|
||||||
|
generate_test_vars(
|
||||||
|
clean=args.clean,
|
||||||
|
repo_root=args.repo_root,
|
||||||
|
test_dir=args.repo_root / args.test_dir,
|
||||||
|
check_attr=args.check_attr,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from clan_cli.generate_test_vars.cli import generate_test_vars
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.with_core
|
||||||
|
def test_generate_test_vars(
|
||||||
|
clan_core: Path,
|
||||||
|
temp_dir: Path,
|
||||||
|
) -> None:
|
||||||
|
test_dir_original = clan_core / "checks/service-dummy-test"
|
||||||
|
service_dir = temp_dir / "service-dummy-test"
|
||||||
|
shutil.copytree(test_dir_original, service_dir)
|
||||||
|
|
||||||
|
# Make the copied tree writable
|
||||||
|
subprocess.run(["chmod", "-R", "+w", str(service_dir)], check=True)
|
||||||
|
|
||||||
|
generate_test_vars(
|
||||||
|
clean=True,
|
||||||
|
repo_root=clan_core,
|
||||||
|
test_dir=service_dir,
|
||||||
|
check_attr="service-dummy-test",
|
||||||
|
)
|
||||||
@@ -28,6 +28,10 @@
|
|||||||
"pkgs/zerotierone"
|
"pkgs/zerotierone"
|
||||||
"pkgs/minifakeroot"
|
"pkgs/minifakeroot"
|
||||||
"pkgs/clan-cli/clan_cli/tests/flake-module.nix"
|
"pkgs/clan-cli/clan_cli/tests/flake-module.nix"
|
||||||
|
|
||||||
|
# needed for test_generate_test_vars.py
|
||||||
|
"checks/service-dummy-test"
|
||||||
|
"checks/flake-module.nix"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Documentation = "https://docs.clan.lol/"
|
|||||||
Repository = "https://git.clan.lol/clan/clan-core"
|
Repository = "https://git.clan.lol/clan/clan-core"
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
include = ["clan_lib*", "clan_cli*", "generate_test_vars*"]
|
include = ["clan_lib*", "clan_cli*"]
|
||||||
exclude = ["clan_lib.nixpkgs*", "result"]
|
exclude = ["clan_lib.nixpkgs*", "result"]
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
|
|||||||
Reference in New Issue
Block a user