mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
Merge pull request #1973 from infinito-nexus/fix/deploy/no-inventory-dump
fix(deploy): never print the inventory file on an invalid application id
This commit is contained in:
2 files changed
+24
-26
No files matched your search
@@ -1,7 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import tempfile
|
||||
import unittest
|
||||
import unittest.mock
|
||||
from pathlib import Path
|
||||
|
||||
from cli.administration.deploy.dedicated import apps
|
||||
|
||||
@@ -30,6 +34,25 @@ class TestValidateApplicationIds(unittest.TestCase):
|
||||
["web-app-foo", "web-app-bar"],
|
||||
)
|
||||
|
||||
@unittest.mock.patch("utils.roles.validation.deploy_id.ValidDeployId")
|
||||
def test_invalid_ids_never_print_the_inventory_content(self, mock_vdi_cls):
|
||||
mock_vdi_cls.return_value.validate.return_value = {
|
||||
"web-app-typo": {"in_roles": False}
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
inventory = Path(tmp) / "devices.yml"
|
||||
inventory.write_text(
|
||||
"all:\n vars:\n ansible_become_password: s3cr3t-marker\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
out = io.StringIO()
|
||||
with contextlib.redirect_stdout(out), self.assertRaises(SystemExit):
|
||||
apps.validate_application_ids(str(inventory), ["web-app-typo"])
|
||||
|
||||
self.assertIn(str(inventory), out.getvalue())
|
||||
self.assertIn("web-app-typo: not defined as a role", out.getvalue())
|
||||
self.assertNotIn("s3cr3t-marker", out.getvalue())
|
||||
|
||||
@unittest.mock.patch("utils.roles.validation.deploy_id.ValidDeployId")
|
||||
def test_valid_ids_do_not_exit(self, mock_vdi_cls):
|
||||
instance = mock_vdi_cls.return_value
|
||||
|
||||
Reference in new issue
Block a user