import re from pathlib import Path def test_argocd_repo_server_copyutil_symlink_is_idempotent(): manifest_path = Path(__file__).resolve().parents[1] / "k8s" / "argocd" / "install.yaml" text = manifest_path.read_text(encoding="utf-8") # Ensure the repo-server initContainer makes the cmp-server symlink idempotently. # The repo-server can be recreated while `/var/run/argocd` is persisted (hostPath), # so an unconditional `ln -s` will fail with "File exists". assert "argocd-cmp-server" in text safe_link_re = re.compile( r"/bin/ln\s+-sf\s+/var/run/argocd/argocd\s+/var/run/argocd/argocd-cmp-server", re.MULTILINE, ) assert safe_link_re.search(text), ( "Expected ArgoCD repo-server copyutil initContainer to use `ln -sf` when creating " "`/var/run/argocd/argocd-cmp-server`." ) unsafe_link_re = re.compile( r"/bin/ln\s+-s\s+/var/run/argocd/argocd\s+/var/run/argocd/argocd-cmp-server", re.MULTILINE, ) assert not unsafe_link_re.search(text), ( "Found an unconditional `ln -s` for `argocd-cmp-server` which is not idempotent." )