This commit is contained in:
84
tests/test_cicd_legacy_cluster_disabled.py
Normal file
84
tests/test_cicd_legacy_cluster_disabled.py
Normal file
@@ -0,0 +1,84 @@
|
||||
from pathlib import Path
|
||||
|
||||
from flask import Flask
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def _client():
|
||||
from routes.cicd_routes import cicd_bp
|
||||
|
||||
app = Flask(__name__, template_folder=str(ROOT / "templates"))
|
||||
app.register_blueprint(cicd_bp)
|
||||
return app.test_client()
|
||||
|
||||
|
||||
def test_cicd_routes_do_not_execute_legacy_cluster_commands():
|
||||
source = (ROOT / "routes" / "cicd_routes.py").read_text(encoding="utf-8")
|
||||
|
||||
assert "kubectl" not in source
|
||||
assert "rollout restart" not in source
|
||||
assert "rollout undo" not in source
|
||||
assert "get_k8s_pods_status" not in source
|
||||
assert "execute_uat_rollback" not in source
|
||||
assert "execute_gcp_rollback" not in source
|
||||
|
||||
|
||||
def test_cicd_restart_pods_action_is_rejected(monkeypatch):
|
||||
from routes import cicd_routes
|
||||
|
||||
def fail_if_called(*args, **kwargs):
|
||||
raise AssertionError("legacy cluster subprocess should not be called")
|
||||
|
||||
monkeypatch.setattr(cicd_routes.subprocess, "run", fail_if_called)
|
||||
|
||||
response = _client().post(
|
||||
"/api/cicd/auto-fix",
|
||||
json={"action": "restart_pods", "environment": "uat"},
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
assert response.get_json()["success"] is False
|
||||
|
||||
|
||||
def test_cicd_rollback_is_disabled(monkeypatch):
|
||||
from routes import cicd_routes
|
||||
|
||||
def fail_if_called(*args, **kwargs):
|
||||
raise AssertionError("legacy cluster subprocess should not be called")
|
||||
|
||||
monkeypatch.setattr(cicd_routes.subprocess, "run", fail_if_called)
|
||||
|
||||
response = _client().post("/api/cicd/rollback", json={"environment": "uat"})
|
||||
|
||||
assert response.status_code == 410
|
||||
payload = response.get_json()
|
||||
assert payload["success"] is False
|
||||
assert "Docker Compose" in payload["error"]
|
||||
|
||||
|
||||
def test_cicd_diagnosis_uses_runtime_note_without_cluster_probe(monkeypatch):
|
||||
from routes import cicd_routes
|
||||
|
||||
class FakeResponse:
|
||||
status_code = 200
|
||||
elapsed = type("Elapsed", (), {"total_seconds": lambda self: 0.05})()
|
||||
|
||||
def json(self):
|
||||
return {"status": "healthy", "version": "test"}
|
||||
|
||||
def fake_get(*args, **kwargs):
|
||||
return FakeResponse()
|
||||
|
||||
def fail_if_called(*args, **kwargs):
|
||||
raise AssertionError("legacy cluster subprocess should not be called")
|
||||
|
||||
monkeypatch.setattr(cicd_routes.requests, "get", fake_get)
|
||||
monkeypatch.setattr(cicd_routes.subprocess, "run", fail_if_called)
|
||||
|
||||
diagnosis = cicd_routes.run_diagnosis("uat")
|
||||
|
||||
runtime_checks = [check for check in diagnosis["checks"] if check["name"] == "Runtime 狀態"]
|
||||
assert runtime_checks
|
||||
assert runtime_checks[0]["runtime"] == "Docker Compose on 192.168.0.188"
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Phase 54 — get_host_label / get_provider_tag 測試覆蓋(P53 新增 fn).
|
||||
|
||||
P53 commit 7a10d27 加了 K8s Nginx Proxy 路由判斷(192.168.0.110:11435/11436)
|
||||
P53 commit 7a10d27 加了 110 Nginx Proxy 路由判斷(192.168.0.110:11435/11436)
|
||||
但無單測,未來改 IP / 加新 provider 容易破而不自知。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -28,11 +28,11 @@ class TestGetHostLabel:
|
||||
assert get_host_label('http://34.21.145.224:11434') == 'GCP-SSD-2'
|
||||
|
||||
def test_nginx_proxy_gcp_primary(self):
|
||||
"""K8s 環境經 110 跳板 Nginx 轉發 GCP-A"""
|
||||
"""經 110 跳板 Nginx 轉發 GCP-A"""
|
||||
assert get_host_label('http://192.168.0.110:11435') == 'GCP-SSD(via Nginx 110)'
|
||||
|
||||
def test_nginx_proxy_gcp_secondary(self):
|
||||
"""K8s 環境經 110 跳板 Nginx 轉發 GCP-B"""
|
||||
"""經 110 跳板 Nginx 轉發 GCP-B"""
|
||||
assert get_host_label('http://192.168.0.110:11436') == 'GCP-SSD-2(via Nginx 110)'
|
||||
|
||||
def test_111_fallback(self):
|
||||
|
||||
Reference in New Issue
Block a user