40 lines
833 B
Go
40 lines
833 B
Go
package user_test
|
|
|
|
import (
|
|
"Crimson-Gatekeeper/internal/common"
|
|
"Crimson-Gatekeeper/internal/query"
|
|
"Crimson-Gatekeeper/internal/user"
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestLogin(t *testing.T) {
|
|
client, clean := common.GetDataBaseClient()
|
|
defer clean()
|
|
gin.SetMode(gin.TestMode)
|
|
app := gin.Default()
|
|
user.New(query.Use(client)).RegisterRoute(app)
|
|
w := httptest.NewRecorder()
|
|
param := gin.H{
|
|
"account": "admin1",
|
|
"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)
|
|
}
|