错误处理中间件

This commit is contained in:
des
2026-01-15 18:57:32 +08:00
parent 69dad45d6a
commit c61fb947e7
4 changed files with 55 additions and 3 deletions

View File

@@ -1,6 +1,10 @@
package user_test
import (
"Crimson-Gatekeeper/internal/common"
"Crimson-Gatekeeper/internal/user"
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
@@ -10,11 +14,27 @@ import (
)
func TestLogin(t *testing.T) {
client, close := common.GetDataBaseClient()
defer close()
gin.SetMode(gin.TestMode)
app := gin.Default()
user.New(client).RegisterRoute(app)
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/api/v1/user/login", nil)
param := gin.H{
"account": "admin",
"password": "123445",
}
data, ero := json.Marshal(param)
if ero != nil {
fmt.Println("序列化失败")
panic(ero)
}
fmt.Println("参数")
fmt.Println(string(data))
req, _ := http.NewRequest("POST", "/api/v1/user/login", bytes.NewReader(data))
app.ServeHTTP(w, req)
fmt.Println("测试结果")
fmt.Println(w)
}