2026-01-14 19:04:01 +08:00
|
|
|
package user_test
|
|
|
|
|
|
|
|
|
|
import (
|
2026-01-15 18:57:32 +08:00
|
|
|
"Crimson-Gatekeeper/internal/common"
|
|
|
|
|
"Crimson-Gatekeeper/internal/user"
|
|
|
|
|
"bytes"
|
|
|
|
|
"encoding/json"
|
2026-01-14 19:04:01 +08:00
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestLogin(t *testing.T) {
|
2026-01-15 18:57:32 +08:00
|
|
|
client, close := common.GetDataBaseClient()
|
|
|
|
|
defer close()
|
|
|
|
|
|
2026-01-14 19:04:01 +08:00
|
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
|
app := gin.Default()
|
2026-01-15 18:57:32 +08:00
|
|
|
user.New(client).RegisterRoute(app)
|
2026-01-14 19:04:01 +08:00
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
2026-01-15 18:57:32 +08:00
|
|
|
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))
|
2026-01-14 19:04:01 +08:00
|
|
|
app.ServeHTTP(w, req)
|
2026-01-15 18:57:32 +08:00
|
|
|
fmt.Println("测试结果")
|
2026-01-14 19:04:01 +08:00
|
|
|
fmt.Println(w)
|
|
|
|
|
}
|