hyapp-deploly/deploy/tencent_tat/tests/test_hyapp_admin_server_deploy.py
2026-07-08 22:33:12 +08:00

46 lines
1.8 KiB
Python

from __future__ import annotations
import argparse
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
from deploy.tencent_tat import hyapp_admin_server_deploy as admin_deploy
class AdminServerDeployScriptTests(unittest.TestCase):
def test_remote_script_pulls_gitea_main_and_verifies_admin_health(self) -> None:
args = argparse.Namespace(
admin_bind_addr="172.16.0.6",
admin_host="134.175.160.86",
admin_instance_id="ins-0x5mjwmc",
admin_port=13100,
admin_region="ap-guangzhou",
branch="main",
dry_run=False,
repo_url="git@gitea.haiyihy.com:hy/hyapp-server.git",
source_dir="/opt/deploy/sources/hyapp-server",
)
script = admin_deploy.build_remote_script(args)
self.assertIn("git fetch --prune origin \"$BRANCH\"", script)
self.assertIn("git checkout -B \"$BRANCH\" \"origin/$BRANCH\"", script)
self.assertIn("git clone \"$REPO_URL\" \"$SOURCE_DIR\"", script)
self.assertIn("GOWORK=off go mod download", script)
self.assertIn("GOWORK=off CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o \"$build_binary\" ./cmd/server", script)
self.assertNotIn("docker build", script)
self.assertNotIn("docker push", script)
self.assertNotIn("docker pull", script)
self.assertNotIn("10.2.1.3:18082", script)
self.assertNotIn("timeout 300 scp", script)
self.assertNotIn("rsync -az --partial", script)
self.assertIn("systemctl restart hyapp-admin-server", script)
self.assertIn("http://$ADMIN_BIND_ADDR:$ADMIN_PORT/healthz", script)
self.assertIn("http://$ADMIN_BIND_ADDR:$ADMIN_PORT/readyz", script)
if __name__ == "__main__":
unittest.main()