feat(admin): initialize procurement service skeleton

This commit is contained in:
QiuSW
2026-08-03 18:13:30 +08:00
parent b7559a9451
commit c72371ce90
11 changed files with 288 additions and 37 deletions
+19
View File
@@ -0,0 +1,19 @@
// Package server 定义采购服务当前拥有的 HTTP 端点。
package server
import (
"net/http"
"github.com/gin-gonic/gin"
)
// NewRouter 返回当前服务范围内的完整 HTTP 路由。
func NewRouter() *gin.Engine {
router := gin.New()
router.GET("/healthz", func(context *gin.Context) {
context.JSON(http.StatusOK, gin.H{"status": "ok"})
})
return router
}
+28
View File
@@ -0,0 +1,28 @@
package server_test
import (
"net/http"
"net/http/httptest"
"testing"
"cmbuyer/admin/internal/server"
)
func TestHealthz(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "/healthz", nil)
response := httptest.NewRecorder()
server.NewRouter().ServeHTTP(response, request)
if response.Code != http.StatusOK {
t.Fatalf("healthz status = %d, want %d", response.Code, http.StatusOK)
}
if contentType := response.Header().Get("Content-Type"); contentType != "application/json; charset=utf-8" {
t.Fatalf("healthz content type = %q, want application/json; charset=utf-8", contentType)
}
if body := response.Body.String(); body != "{\"status\":\"ok\"}" {
t.Fatalf("healthz body = %q, want {\"status\":\"ok\"}", body)
}
}