Files
Crimson-Gatekeeper/srv/internal/user/controller_test.go

40 lines
833 B
Go
Raw Normal View History

2026-01-14 19:04:01 +08:00
package user_test
import (
2026-01-15 18:57:32 +08:00
"Crimson-Gatekeeper/internal/common"
2026-01-19 00:07:20 +08:00
"Crimson-Gatekeeper/internal/query"
2026-01-15 18:57:32 +08:00
"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-19 00:07:20 +08:00
client, clean := common.GetDataBaseClient()
defer clean()
2026-01-14 19:04:01 +08:00
gin.SetMode(gin.TestMode)
app := gin.Default()
2026-01-19 00:07:20 +08:00
user.New(query.Use(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{
2026-01-19 00:07:20 +08:00
"account": "admin1",
2026-01-15 18:57:32 +08:00
"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)
}