fusenapi/server/home-user-auth/test/userstatusconfiglogic_test.go

57 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package homeuserauthtest
import (
"fmt"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"
"github.com/tidwall/gjson"
)
func TestCaseUserStatusConfigLogic(t *testing.T) {
var err error
var resp *requests.Response
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
// 向服务器发送 GET 请求,获取用户类型信息
resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/status-config", cnf.Host, cnf.Port)).TestExecute(gserver)
if err != nil {
t.Error(err)
}
// 使用 gjson 解析返回的 json 数据
result = gjson.Parse(resp.ContentString())
// 检查返回值中的 code 字段是否存在,并且值是否为 200
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
msg := result.Get("msg").String()
if msg != "success" {
t.Errorf(`Invalid msg value: "%s"`, msg)
}
// 检查返回值中的 data 字段是否存在,并且值是否为数组类型
dataArray := result.Get("data.search_list").Array()
if len(dataArray) == 0 {
t.Error("Empty data field")
}
// 遍历每个元素,检查其 key name 字段是否存在,并且值是否符合预期
for _, item := range dataArray {
key := item.Get("key")
name := item.Get("name")
if !key.Exists() {
t.Errorf("key is not exists")
}
if !name.Exists() {
t.Errorf("name is not exists")
}
}
}