Files
likang 7ddc3c22c5
CI / typecheck + test + build (push) Has been cancelled
commit
2026-11-16 17:50:15 +08:00

44 lines
1.5 KiB
Python

"""The deployment command must not report success for unhealthy containers."""
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
SCRIPT = Path(__file__).resolve().parents[1] / 'deploy.sh'
class Deployment(unittest.TestCase):
def run_deploy(self, healthy):
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
docker = root / 'docker'
docker.write_text(f'#!{sys.executable}\n' + '''import os,sys
args=sys.argv[1:]
if 'up' in args:
assert '--wait' in args and '--wait-timeout' in args
sys.exit(0 if os.environ['TEST_HEALTHY']=='1' else 42)
print('container runtime: BRIDGE_NOT_READY')
''')
docker.chmod(0o755)
return subprocess.run(['/bin/sh', str(SCRIPT)],
env={'PATH': str(root)+os.pathsep+os.defpath, 'TEST_HEALTHY': '1' if healthy else '0'},
capture_output=True, text=True, timeout=5)
def test_failed_readiness_fails_deployment_and_prints_evidence(self):
result = self.run_deploy(False)
self.assertNotEqual(result.returncode, 0)
self.assertIn('deployment failed', result.stderr)
self.assertIn('BRIDGE_NOT_READY', result.stdout)
self.assertNotIn('deployment ready:', result.stdout)
def test_only_successful_healthcheck_reports_ready(self):
result = self.run_deploy(True)
self.assertEqual(result.returncode, 0)
self.assertIn('deployment ready:', result.stdout)
if __name__ == '__main__':
unittest.main()