Checks / verify (push) Failing after 9m52s
统一单入口 Go 工程与前端依赖目录,增加后台供应商配置、候选审核、计划预算、成交冲正、持仓复盘和站内通知。接入策略版本、Python 回测、可配置 A 股公开行情及 zap 文件轮转日志,补充迁移、契约与验证。
68 lines
2.4 KiB
Go
68 lines
2.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"go.uber.org/zap"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.sundynix.cn/Blizzard/Veyra/internal/service"
|
|
)
|
|
|
|
func TestLivenessAndReadinessAreIndependent(t *testing.T) {
|
|
secretError := "password=secret-internal-detail"
|
|
health := service.NewHealthService(nil, func(context.Context) error { return errors.New(secretError) })
|
|
router := NewRouter(health, zap.NewNop(), IdentityOptions{})
|
|
for _, tc := range []struct {
|
|
path string
|
|
status int
|
|
}{{"/healthz", http.StatusOK}, {"/readyz", http.StatusServiceUnavailable}, {"/api/v1/system/health", http.StatusServiceUnavailable}} {
|
|
rec := httptest.NewRecorder()
|
|
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, tc.path, nil))
|
|
if rec.Code != tc.status {
|
|
t.Fatalf("%s: got %d", tc.path, rec.Code)
|
|
}
|
|
if strings.Contains(rec.Body.String(), secretError) {
|
|
t.Fatal("health endpoint leaked internal error")
|
|
}
|
|
if rec.Header().Get("X-Request-ID") == "" {
|
|
t.Fatal("missing trace ID")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestReadyWhenBothDependenciesRespond(t *testing.T) {
|
|
probe := func(context.Context) error { return nil }
|
|
router := NewRouter(service.NewHealthService(probe, probe), zap.NewNop(), IdentityOptions{})
|
|
rec := httptest.NewRecorder()
|
|
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/readyz", nil))
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("got %d", rec.Code)
|
|
}
|
|
}
|
|
|
|
func TestEmbeddedConsoleAndAPIBoundary(t *testing.T) {
|
|
probe := func(context.Context) error { return nil }
|
|
router := NewRouter(service.NewHealthService(probe, probe), zap.NewNop(), IdentityOptions{})
|
|
for _, path := range []string{"/", "/research/candidates"} {
|
|
rec := httptest.NewRecorder()
|
|
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil))
|
|
if rec.Code == http.StatusServiceUnavailable {
|
|
t.Skip("build management console before testing embedded assets")
|
|
}
|
|
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), "<html") {
|
|
t.Fatalf("embedded SPA %s: status=%d", path, rec.Code)
|
|
}
|
|
}
|
|
for _, path := range []string{"/api/v1/missing", "/assets/missing.js", "/.keep"} {
|
|
rec := httptest.NewRecorder()
|
|
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil))
|
|
if rec.Code != http.StatusNotFound || strings.Contains(rec.Body.String(), "<html") {
|
|
t.Fatalf("missing route %s must not serve the SPA: %d", path, rec.Code)
|
|
}
|
|
}
|
|
}
|