2023-07-06 10:23:43 +00:00
|
|
|
|
package homeuserauthtest
|
2023-06-16 02:58:43 +00:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2023-07-05 11:00:33 +00:00
|
|
|
|
fstests "fusenapi/utils/fstests"
|
2023-06-16 02:58:43 +00:00
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/474420502/requests"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCaseUserFontsLogic(t *testing.T) {
|
2023-06-19 07:52:14 +00:00
|
|
|
|
|
2023-06-16 02:58:43 +00:00
|
|
|
|
var err error
|
|
|
|
|
var resp *requests.Response
|
|
|
|
|
var result gjson.Result
|
|
|
|
|
|
|
|
|
|
// 获取 session,并携带 JWT token
|
2023-07-24 11:17:02 +00:00
|
|
|
|
ses := fstests.GetSessionWithUserToken(t, userserver, cnf.Host, cnf.Port)
|
2023-06-16 02:58:43 +00:00
|
|
|
|
|
|
|
|
|
// 向服务器发送 GET 请求,获取字体列表
|
2023-07-24 11:17:02 +00:00
|
|
|
|
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/api/user/fonts", cnf.Host, cnf.Port)).TestExecute(gserver)
|
2023-06-16 02:58:43 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用 gjson 解析返回的 json 数据
|
2023-06-16 10:52:24 +00:00
|
|
|
|
result = resp.Json() // func (*requests.Response).Json() gjson.Result
|
2023-06-16 02:58:43 +00:00
|
|
|
|
|
|
|
|
|
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
|
|
|
|
code := result.Get("code").Int()
|
|
|
|
|
if code != 200 {
|
|
|
|
|
t.Errorf("Invalid code value: %d", code)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
|
|
|
|
msg := result.Get("msg").String()
|
|
|
|
|
if msg != "success" {
|
|
|
|
|
t.Errorf(`Invalid msg value: "%s"`, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查返回值中的 data 字段是否存在,并且值是否为数组类型
|
|
|
|
|
dataArray := result.Get("data").Array()
|
|
|
|
|
if len(dataArray) == 0 {
|
|
|
|
|
t.Error("Empty data field")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历每个元素,检查其 key 和 name 字段是否存在,并且值是否符合预期
|
2023-06-19 07:52:14 +00:00
|
|
|
|
for _, item := range dataArray {
|
|
|
|
|
// log.Println(item)
|
2023-06-16 02:58:43 +00:00
|
|
|
|
|
2023-06-19 07:52:14 +00:00
|
|
|
|
if !item.Get("id").Exists() {
|
|
|
|
|
t.Error("id is not exists")
|
2023-06-16 02:58:43 +00:00
|
|
|
|
}
|
2023-06-19 07:52:14 +00:00
|
|
|
|
if !item.Get("title").Exists() {
|
|
|
|
|
t.Error("title is not exists")
|
|
|
|
|
}
|
|
|
|
|
if !item.Get("linux_fontname").Exists() {
|
|
|
|
|
t.Error("linux_fontname is not exists")
|
|
|
|
|
}
|
|
|
|
|
if !item.Get("file_path").Exists() {
|
|
|
|
|
t.Error("file_path is not exists")
|
|
|
|
|
}
|
|
|
|
|
if !item.Get("sort").Exists() {
|
|
|
|
|
t.Error("sort is not exists")
|
2023-06-16 02:58:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|