webset 单元测试完成, 缺少font_config的测试例子

This commit is contained in:
eson 2023-06-25 13:15:55 +08:00
parent aceb4c926f
commit 6bfa46e990
8 changed files with 106 additions and 69 deletions

View File

@ -7,6 +7,7 @@ const (
POLICY_CONFIG TypeWebSet = "policy" //政策
CLAUSE_CONFIG TypeWebSet = "clause" //条款
FAQ_CONFIG TypeWebSet = "faq" //问答
RECOMMEND_DETAIL_PRODUCT TypeWebSet = "recommend_detail_" //详情页推荐-后街pid
RENDER_DESIGN TypeWebSet = "render_design_" //云渲染 后接client_no
LAST_DESIGN TypeWebSet = "last_design_" //最后设计 后接uid

4
go.mod
View File

@ -7,6 +7,7 @@ require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/stripe/stripe-go/v74 v74.22.0
github.com/zeromicro/go-zero v1.5.2
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
gorm.io/driver/mysql v1.5.1
@ -16,11 +17,10 @@ require (
require (
github.com/google/uuid v1.3.0 // indirect
github.com/schollz/progressbar v1.0.0 // indirect
github.com/stripe/stripe-go/v74 v74.22.0 // indirect
)
require (
github.com/474420502/requests v1.33.0
github.com/474420502/requests v1.33.3
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/tidwall/gjson v1.12.0

4
go.sum
View File

@ -32,8 +32,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/474420502/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoKU=
github.com/474420502/requests v1.33.0 h1:psSTM9WsIDjbjJIXXXhhT52BlpcaNs+gDetQi2wgu1o=
github.com/474420502/requests v1.33.0/go.mod h1:5qAlksMg7JIrEXrpkxw1++4Z5W2tUkZbHA6M7oq1r/0=
github.com/474420502/requests v1.33.3 h1:CZs7M9OoaDMTJBCPQh4kob+rgFp2R9vHVZD0kaVDdrs=
github.com/474420502/requests v1.33.3/go.mod h1:5qAlksMg7JIrEXrpkxw1++4Z5W2tUkZbHA6M7oq1r/0=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=

View File

@ -17,10 +17,10 @@ var gserver *rest.Server
func init() {
log.SetFlags(log.Llongfile)
gserver = GetTestServer(testConfigFile)
gserver = GetTestServer()
}
func GetTestServer(testConfigFile string) *rest.Server {
func GetTestServer() *rest.Server {
conf.MustLoad(testConfigFile, &cnf)

View File

@ -1,7 +1,7 @@
Name: wetset
Host: 0.0.0.0
Port: 8888
SourceMysql: ""
SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest"
Auth:
AccessSecret: fusen2023
AccessExpire: 604800

View File

@ -5,7 +5,6 @@ import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"strings"
"context"
@ -51,36 +50,6 @@ func (l *WetSetSettingLogic) WetSetSetting(req *types.RequestWebSet, userinfo *a
if err != nil {
return resp.SetStatus(basic.CodeJsonErr)
}
//组装配置项的内容数据
for k, v := range result["list"].(map[string]interface{}) {
//按空格分隔内容
result["list"].(map[string]interface{})[k].(map[string]interface{})["content"] = strings.Split(v.(string), "\n")
}
// TODO: 缓存
if typeConf == constants.CLAUSE_CONFIG || typeConf == constants.FAQ_CONFIG || typeConf == constants.POLICY_CONFIG {
// cache := redis.NewClient(&redis.Options{
// Addr: "localhost:6379",
// Password: "", // no password set
// DB: 0, // use default DB
// })
// if cache.Exists(ctx.Query("type")).Val() > 0 {
// result = cache.HGetAll(ctx.Query("type")).Val()
// } else {
// //读取配置项
// model := WebSet{Key: typeStr}
// db.First(&model)
// result = json.Unmarshal([]byte(model.Value), &result)
// //组装配置项的内容数据
// for k, v := range result["list"].(map[string]interface{}) {
// //按空格分隔内容
// result["list"].(map[string]interface{})[k].(map[string]interface{})["content"] = strings.Split(v.(string), "\n")
// }
// cache.HMSet(ctx.Query("type"), result)
// }
} else {
}
return resp.SetStatus(basic.CodeOK)
return resp.SetStatus(basic.CodeOK, result)
}

View File

@ -17,10 +17,10 @@ var gserver *rest.Server
func init() {
log.SetFlags(log.Llongfile)
gserver = GetTestServer(testConfigFile)
gserver = GetTestServer()
}
func GetTestServer(testConfigFile string) *rest.Server {
func GetTestServer() *rest.Server {
conf.MustLoad(testConfigFile, &cnf)

View File

@ -2,8 +2,8 @@ package logic
import (
"fmt"
"fusenapi/constants"
fstests "fusenapi/utils/tests"
"log"
"testing"
"github.com/474420502/requests"
@ -15,10 +15,18 @@ func TestWetSetLogic(t *testing.T) {
var resp *requests.Response
var result gjson.Result
// constants.FONT_CONFIG ? 这个还没有测试的例子
testTypes := []constants.TypeWebSet{constants.POLICY_CONFIG, constants.CLAUSE_CONFIG, constants.FAQ_CONFIG}
// 获取 session并携带 JWT token
ses := fstests.GetSesssion()
tp := ses.Get(fmt.Sprintf("http://%s:%d/web-set/setting", cnf.Host, cnf.Port))
for _, tType := range testTypes {
tp.QueryParam("type").Set(tType)
// log.Println(tp.GetRawURL())
// 向服务器发送 GET 请求,获取 cookie 信息
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/wet-set/setting", cnf.Host, cnf.Port)).TestExecute(gserver)
resp, err = tp.TestExecute(gserver)
if err != nil {
t.Error(err)
}
@ -26,22 +34,81 @@ func TestWetSetLogic(t *testing.T) {
// 使用 gjson 解析返回的 json 数据
result = resp.Json() // gjson
log.Println(result)
// log.Println(result)
// 检查返回值中的 code 字段是否存在,并且值是否为 200
code := result.Get("code").Int()
if code != 200 {
t.Errorf("Invalid code value: %d", code)
result = result.Get("code")
if !result.Exists() {
t.Error("code is not exists")
}
if result.Int() != 200 {
t.Error("code != 200")
}
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
msg := result.Get("msg").String()
if msg != "success" {
t.Errorf(`Invalid msg value: "%s"`, msg)
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
result = resp.Json().Get("msg")
if !result.Exists() {
t.Error("msg is not exists")
}
if result.String() != "success" {
t.Error(result.String())
}
// 检查返回值中的 data 字段是否存在,并且值是否符合预期
token := result.Get("data.token").String()
if len(token) == 0 {
t.Error("Missing token field")
// 检查返回值中的 data 字段是否存在
result = resp.Json().Get("data")
if !result.Exists() {
t.Error("data is not exists")
}
// 根据data的不同,分别校验
intro := result.Get("introduction")
if intro.Exists() {
// 如果有introduction,则校验introduction和list
if !intro.Exists() {
t.Error("introduction is not exists")
}
list := result.Get("list")
if !list.Exists() {
t.Error("list is not exists")
}
// ...
} else {
// 如果没有introduction,则校验icon、items和title
icon := result.Get("icon")
if !icon.Exists() {
t.Error("icon is not exists")
}
items := result.Get("items")
if !items.Exists() {
t.Error("items is not exists")
}
title := result.Get("title")
if !title.Exists() {
t.Error("title is not exists")
}
// ...
}
}
// 检查返回值中的 introduction 字段是否存在
// intro := result.Get("introduction")
// if !intro.Exists() {
// t.Error("introduction is not exists")
// }
// // 检查返回值中的 list 数组是否存在
// list := result.Get("list")
// if !list.Exists() {
// t.Error("list is not exists")
// }
// // 校验 list 数组中的每个条款 title 和 content 字段是否存在
// for _, item := range list.Array() {
// title := item.Get("title")
// content := item.Get("content")
// if !title.Exists() || !content.Exists() {
// t.Error("title or content not exists")
// log.Println(result)
// continue
// }
// }
}