错误处理中间件
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user