guanghu-ice-heart/server-tools/persona-compute-pool/test_entry_service.py

17 lines
1,001 B
Python
Raw Normal View History

#!/usr/bin/env python3
import importlib.util, json, tempfile, unittest
from pathlib import Path
ROOT=Path(__file__).resolve().parents[2]
spec=importlib.util.spec_from_file_location('entry',ROOT/'server-tools/persona-compute-pool/entry_service.py'); M=importlib.util.module_from_spec(spec); assert spec.loader; spec.loader.exec_module(M)
class EntryServiceTests(unittest.TestCase):
def test_mother_node_is_forbidden(self):
with tempfile.TemporaryDirectory() as tmp:
old=M.STATE; M.STATE=Path(tmp)/'state.json'; M.write_state(M.read_state()); self.assertFalse('JD-FD-PRIMARY' in M.read_state()['workers']); M.STATE=old
def test_state_has_authority_false(self):
value=M.read_state(); self.assertFalse(value['authority_granted'])
def test_worker_certificate_identity_is_required_by_contract(self):
self.assertIn('MTLS_CLIENT_CERT_REQUIRED', open(ROOT/'server-tools/persona-compute-pool/entry_service.py').read())
if __name__=='__main__': unittest.main()