test(gitops,appctl): split deployments.yaml path tests into single-behavior cases
Core Architecture & Invariant CI / validate (pull_request) Successful in 5m8s
Core Architecture & Invariant CI / validate (pull_request) Successful in 5m8s
- Split test_deployments_file_defaults_to_workloads_and_does_not_fallback in tests/security/test_gitops_security.py into 3 single-behavior tests - Split test_default_deployments_file_resolves_to_workloads_dir in tests/unit/test_appctl_auth.py into 3 single-behavior tests - Split test_daemon_deployments_file_defaults_to_workloads_and_honors_override in tests/unit/test_appctl_daemon.py into 2 single-behavior tests
This commit is contained in:
1 parent
9306dae56b
commit
7d4cfe1c04
3 files changed
+45
-20
No files matched your search
@@ -269,17 +269,20 @@ def test_registry_resolves_workloads_and_sites_tilde_prefixes(
|
|||||||
assert gitops_dispatcher.resolve_repository("valid") is None
|
assert gitops_dispatcher.resolve_repository("valid") is None
|
||||||
|
|
||||||
|
|
||||||
def test_deployments_file_defaults_to_workloads_and_does_not_fallback(
|
def test_deployments_file_defaults_to_workloads(
|
||||||
tmp_path: Path, monkeypatch, run_isolated_script_expr
|
tmp_path: Path, run_isolated_script_expr
|
||||||
):
|
):
|
||||||
"""Ensure DEPLOYMENTS_FILE defaults to ~/Workloads/deployments.yaml and fails closed without CONFIG_DIR/CORE_DIR fallback."""
|
"""Ensure DEPLOYMENTS_FILE defaults to ~/Workloads/deployments.yaml."""
|
||||||
resolved_default = run_isolated_script_expr(
|
resolved_default = run_isolated_script_expr(
|
||||||
"import gitops_dispatcher; print(gitops_dispatcher.DEPLOYMENTS_FILE)"
|
"import gitops_dispatcher; print(gitops_dispatcher.DEPLOYMENTS_FILE)"
|
||||||
)
|
)
|
||||||
expected_default = tmp_path / "Workloads" / "deployments.yaml"
|
assert Path(resolved_default) == tmp_path / "Workloads" / "deployments.yaml"
|
||||||
assert Path(resolved_default) == expected_default
|
|
||||||
|
|
||||||
# Even if CONFIG_DIR/deployments.yaml exists, missing DEPLOYMENTS_FILE must fail closed
|
|
||||||
|
def test_deployments_file_fails_closed_without_config_dir_fallback(
|
||||||
|
tmp_path: Path, monkeypatch
|
||||||
|
):
|
||||||
|
"""Ensure missing DEPLOYMENTS_FILE fails closed even when CONFIG_DIR/deployments.yaml exists."""
|
||||||
config_dir = tmp_path / "config-fallback"
|
config_dir = tmp_path / "config-fallback"
|
||||||
config_dir.mkdir()
|
config_dir.mkdir()
|
||||||
(config_dir / "deployments.yaml").write_text(
|
(config_dir / "deployments.yaml").write_text(
|
||||||
@@ -289,11 +292,17 @@ def test_deployments_file_defaults_to_workloads_and_does_not_fallback(
|
|||||||
' path: "~/Workloads/docs"\n',
|
' path: "~/Workloads/docs"\n',
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
monkeypatch.setattr(gitops_dispatcher, "DEPLOYMENTS_FILE", expected_default)
|
monkeypatch.setattr(
|
||||||
|
gitops_dispatcher, "DEPLOYMENTS_FILE", tmp_path / "Workloads" / "deployments.yaml"
|
||||||
|
)
|
||||||
monkeypatch.setattr(gitops_dispatcher, "CONFIG_DIR", config_dir)
|
monkeypatch.setattr(gitops_dispatcher, "CONFIG_DIR", config_dir)
|
||||||
assert gitops_dispatcher.get_trusted_repository_mapping() == {}
|
assert gitops_dispatcher.get_trusted_repository_mapping() == {}
|
||||||
|
|
||||||
# WORKLOADS_DIR override when HOMELAB_DEPLOYMENTS_FILE is unset
|
|
||||||
|
def test_deployments_file_honors_workloads_dir_override(
|
||||||
|
tmp_path: Path, run_isolated_script_expr
|
||||||
|
):
|
||||||
|
"""Ensure DEPLOYMENTS_FILE honors WORKLOADS_DIR override when HOMELAB_DEPLOYMENTS_FILE is unset."""
|
||||||
custom_workloads = tmp_path / "CustomWorkloads"
|
custom_workloads = tmp_path / "CustomWorkloads"
|
||||||
resolved_override = run_isolated_script_expr(
|
resolved_override = run_isolated_script_expr(
|
||||||
"import gitops_dispatcher; print(gitops_dispatcher.DEPLOYMENTS_FILE)",
|
"import gitops_dispatcher; print(gitops_dispatcher.DEPLOYMENTS_FILE)",
|
||||||
|
|||||||
@@ -495,30 +495,42 @@ def test_rbac_viewer_denied_on_sensitive_reads():
|
|||||||
|
|
||||||
|
|
||||||
def test_default_deployments_file_resolves_to_workloads_dir(
|
def test_default_deployments_file_resolves_to_workloads_dir(
|
||||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, run_isolated_script_expr
|
tmp_path: Path, run_isolated_script_expr
|
||||||
):
|
):
|
||||||
"""DEFAULT_DEPLOYMENTS_FILE defaults to ~/Workloads/deployments.yaml and fails closed when absent."""
|
"""DEFAULT_DEPLOYMENTS_FILE defaults to ~/Workloads/deployments.yaml."""
|
||||||
import appctl_auth
|
|
||||||
|
|
||||||
resolved = run_isolated_script_expr(
|
resolved = run_isolated_script_expr(
|
||||||
"import appctl_auth; print(appctl_auth.DEFAULT_DEPLOYMENTS_FILE)"
|
"import appctl_auth; print(appctl_auth.DEFAULT_DEPLOYMENTS_FILE)"
|
||||||
)
|
)
|
||||||
expected = tmp_path / "Workloads" / "deployments.yaml"
|
assert Path(resolved) == tmp_path / "Workloads" / "deployments.yaml"
|
||||||
assert Path(resolved) == expected
|
|
||||||
|
|
||||||
|
def test_load_admitted_workloads_fails_closed_when_absent(
|
||||||
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||||
|
):
|
||||||
|
"""Absent ~/Workloads/deployments.yaml fails closed (empty set, no CORE_DIR fallback)."""
|
||||||
|
import appctl_auth
|
||||||
|
|
||||||
# Absent ~/Workloads/deployments.yaml must fail closed (no CORE_DIR fallback)
|
|
||||||
monkeypatch.delenv("HOMELAB_DEPLOYMENTS_FILE", raising=False)
|
monkeypatch.delenv("HOMELAB_DEPLOYMENTS_FILE", raising=False)
|
||||||
monkeypatch.delenv("WORKLOADS_DIR", raising=False)
|
monkeypatch.delenv("WORKLOADS_DIR", raising=False)
|
||||||
monkeypatch.delenv("SITES_DIR", raising=False)
|
monkeypatch.delenv("SITES_DIR", raising=False)
|
||||||
monkeypatch.setattr(appctl_auth, "DEFAULT_DEPLOYMENTS_FILE", expected)
|
monkeypatch.setattr(
|
||||||
|
appctl_auth, "DEFAULT_DEPLOYMENTS_FILE", tmp_path / "Workloads" / "deployments.yaml"
|
||||||
|
)
|
||||||
assert appctl_auth.load_admitted_workloads() == set()
|
assert appctl_auth.load_admitted_workloads() == set()
|
||||||
|
|
||||||
# WORKLOADS_DIR takes precedence when HOMELAB_DEPLOYMENTS_FILE is unset
|
|
||||||
|
def test_load_admitted_workloads_honors_workloads_dir_override(
|
||||||
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||||
|
):
|
||||||
|
"""WORKLOADS_DIR takes precedence when HOMELAB_DEPLOYMENTS_FILE is unset."""
|
||||||
|
import appctl_auth
|
||||||
|
|
||||||
custom_workloads = tmp_path / "CustomWorkloads"
|
custom_workloads = tmp_path / "CustomWorkloads"
|
||||||
custom_workloads.mkdir()
|
custom_workloads.mkdir()
|
||||||
(custom_workloads / "deployments.yaml").write_text(
|
(custom_workloads / "deployments.yaml").write_text(
|
||||||
"repositories:\n custom_app:\n path: ~/Workloads/custom_app\n",
|
"repositories:\n custom_app:\n path: ~/Workloads/custom_app\n",
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
|
monkeypatch.delenv("HOMELAB_DEPLOYMENTS_FILE", raising=False)
|
||||||
monkeypatch.setenv("WORKLOADS_DIR", str(custom_workloads))
|
monkeypatch.setenv("WORKLOADS_DIR", str(custom_workloads))
|
||||||
assert appctl_auth.load_admitted_workloads() == {"custom_app"}
|
assert appctl_auth.load_admitted_workloads() == {"custom_app"}
|
||||||
@@ -593,16 +593,20 @@ def test_gitops_dispatcher_delegates_to_daemon(daemon_env, monkeypatch):
|
|||||||
assert mock_sub.call_count >= 1
|
assert mock_sub.call_count >= 1
|
||||||
|
|
||||||
|
|
||||||
def test_daemon_deployments_file_defaults_to_workloads_and_honors_override(
|
def test_daemon_deployments_file_defaults_to_workloads(
|
||||||
tmp_path: Path, run_isolated_script_expr
|
tmp_path: Path, run_isolated_script_expr
|
||||||
):
|
):
|
||||||
"""DEPLOYMENTS_FILE defaults to ~/Workloads/deployments.yaml and honors WORKLOADS_DIR override."""
|
"""DEPLOYMENTS_FILE defaults to ~/Workloads/deployments.yaml."""
|
||||||
resolved_default = run_isolated_script_expr(
|
resolved_default = run_isolated_script_expr(
|
||||||
"import appctl_daemon; print(appctl_daemon.DEPLOYMENTS_FILE)"
|
"import appctl_daemon; print(appctl_daemon.DEPLOYMENTS_FILE)"
|
||||||
)
|
)
|
||||||
assert Path(resolved_default) == tmp_path / "Workloads" / "deployments.yaml"
|
assert Path(resolved_default) == tmp_path / "Workloads" / "deployments.yaml"
|
||||||
|
|
||||||
# WORKLOADS_DIR override when HOMELAB_DEPLOYMENTS_FILE is unset
|
|
||||||
|
def test_daemon_deployments_file_honors_workloads_dir_override(
|
||||||
|
tmp_path: Path, run_isolated_script_expr
|
||||||
|
):
|
||||||
|
"""DEPLOYMENTS_FILE honors WORKLOADS_DIR override when HOMELAB_DEPLOYMENTS_FILE is unset."""
|
||||||
custom_workloads = tmp_path / "CustomWorkloads"
|
custom_workloads = tmp_path / "CustomWorkloads"
|
||||||
resolved_override = run_isolated_script_expr(
|
resolved_override = run_isolated_script_expr(
|
||||||
"import appctl_daemon; print(appctl_daemon.DEPLOYMENTS_FILE)",
|
"import appctl_daemon; print(appctl_daemon.DEPLOYMENTS_FILE)",
|
||||||
|
|||||||
Reference in new issue
Block a user