webset 单元测试完成, 缺少font_config的测试例子
This commit is contained in:
parent
aceb4c926f
commit
6bfa46e990
|
@ -3,10 +3,11 @@ package constants
|
||||||
type TypeWebSet string
|
type TypeWebSet string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FONT_CONFIG TypeWebSet = "font_config" //字体
|
FONT_CONFIG TypeWebSet = "font_config" //字体
|
||||||
POLICY_CONFIG TypeWebSet = "policy" //政策
|
POLICY_CONFIG TypeWebSet = "policy" //政策
|
||||||
CLAUSE_CONFIG TypeWebSet = "clause" //条款
|
CLAUSE_CONFIG TypeWebSet = "clause" //条款
|
||||||
FAQ_CONFIG TypeWebSet = "faq" //问答
|
FAQ_CONFIG TypeWebSet = "faq" //问答
|
||||||
|
|
||||||
RECOMMEND_DETAIL_PRODUCT TypeWebSet = "recommend_detail_" //详情页推荐-后街pid
|
RECOMMEND_DETAIL_PRODUCT TypeWebSet = "recommend_detail_" //详情页推荐-后街pid
|
||||||
RENDER_DESIGN TypeWebSet = "render_design_" //云渲染 后接client_no
|
RENDER_DESIGN TypeWebSet = "render_design_" //云渲染 后接client_no
|
||||||
LAST_DESIGN TypeWebSet = "last_design_" //最后设计 后接uid
|
LAST_DESIGN TypeWebSet = "last_design_" //最后设计 后接uid
|
||||||
|
|
4
go.mod
4
go.mod
|
@ -7,6 +7,7 @@ require (
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
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
|
github.com/zeromicro/go-zero v1.5.2
|
||||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
|
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
|
||||||
gorm.io/driver/mysql v1.5.1
|
gorm.io/driver/mysql v1.5.1
|
||||||
|
@ -16,11 +17,10 @@ require (
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/schollz/progressbar v1.0.0 // indirect
|
github.com/schollz/progressbar v1.0.0 // indirect
|
||||||
github.com/stripe/stripe-go/v74 v74.22.0 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
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/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/tidwall/gjson v1.12.0
|
github.com/tidwall/gjson v1.12.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -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=
|
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=
|
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/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoKU=
|
||||||
github.com/474420502/requests v1.33.0 h1:psSTM9WsIDjbjJIXXXhhT52BlpcaNs+gDetQi2wgu1o=
|
github.com/474420502/requests v1.33.3 h1:CZs7M9OoaDMTJBCPQh4kob+rgFp2R9vHVZD0kaVDdrs=
|
||||||
github.com/474420502/requests v1.33.0/go.mod h1:5qAlksMg7JIrEXrpkxw1++4Z5W2tUkZbHA6M7oq1r/0=
|
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/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/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=
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
|
|
|
@ -17,10 +17,10 @@ var gserver *rest.Server
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.Llongfile)
|
log.SetFlags(log.Llongfile)
|
||||||
gserver = GetTestServer(testConfigFile)
|
gserver = GetTestServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTestServer(testConfigFile string) *rest.Server {
|
func GetTestServer() *rest.Server {
|
||||||
|
|
||||||
conf.MustLoad(testConfigFile, &cnf)
|
conf.MustLoad(testConfigFile, &cnf)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Name: wetset
|
Name: wetset
|
||||||
Host: 0.0.0.0
|
Host: 0.0.0.0
|
||||||
Port: 8888
|
Port: 8888
|
||||||
SourceMysql: ""
|
SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest"
|
||||||
Auth:
|
Auth:
|
||||||
AccessSecret: fusen2023
|
AccessSecret: fusen2023
|
||||||
AccessExpire: 604800
|
AccessExpire: 604800
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
@ -51,36 +50,6 @@ func (l *WetSetSettingLogic) WetSetSetting(req *types.RequestWebSet, userinfo *a
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp.SetStatus(basic.CodeJsonErr)
|
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: 缓存
|
return resp.SetStatus(basic.CodeOK, result)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,10 @@ var gserver *rest.Server
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.Llongfile)
|
log.SetFlags(log.Llongfile)
|
||||||
gserver = GetTestServer(testConfigFile)
|
gserver = GetTestServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTestServer(testConfigFile string) *rest.Server {
|
func GetTestServer() *rest.Server {
|
||||||
|
|
||||||
conf.MustLoad(testConfigFile, &cnf)
|
conf.MustLoad(testConfigFile, &cnf)
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"fusenapi/constants"
|
||||||
fstests "fusenapi/utils/tests"
|
fstests "fusenapi/utils/tests"
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/474420502/requests"
|
"github.com/474420502/requests"
|
||||||
|
@ -15,33 +15,100 @@ func TestWetSetLogic(t *testing.T) {
|
||||||
var resp *requests.Response
|
var resp *requests.Response
|
||||||
var result gjson.Result
|
var result gjson.Result
|
||||||
|
|
||||||
|
// constants.FONT_CONFIG ? 这个还没有测试的例子
|
||||||
|
testTypes := []constants.TypeWebSet{constants.POLICY_CONFIG, constants.CLAUSE_CONFIG, constants.FAQ_CONFIG}
|
||||||
|
|
||||||
// 获取 session,并携带 JWT token
|
// 获取 session,并携带 JWT token
|
||||||
ses := fstests.GetSesssion()
|
ses := fstests.GetSesssion()
|
||||||
// 向服务器发送 GET 请求,获取 cookie 信息
|
tp := ses.Get(fmt.Sprintf("http://%s:%d/web-set/setting", cnf.Host, cnf.Port))
|
||||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/wet-set/setting", cnf.Host, cnf.Port)).TestExecute(gserver)
|
|
||||||
if err != nil {
|
for _, tType := range testTypes {
|
||||||
t.Error(err)
|
tp.QueryParam("type").Set(tType)
|
||||||
|
// log.Println(tp.GetRawURL())
|
||||||
|
// 向服务器发送 GET 请求,获取 cookie 信息
|
||||||
|
resp, err = tp.TestExecute(gserver)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用 gjson 解析返回的 json 数据
|
||||||
|
result = resp.Json() // gjson
|
||||||
|
|
||||||
|
// log.Println(result)
|
||||||
|
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
||||||
|
result = result.Get("code")
|
||||||
|
if !result.Exists() {
|
||||||
|
t.Error("code is not exists")
|
||||||
|
}
|
||||||
|
if result.Int() != 200 {
|
||||||
|
t.Error("code != 200")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查返回值中的 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 字段是否存在
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用 gjson 解析返回的 json 数据
|
// 检查返回值中的 introduction 字段是否存在
|
||||||
result = resp.Json() // gjson
|
// intro := result.Get("introduction")
|
||||||
|
// if !intro.Exists() {
|
||||||
|
// t.Error("introduction is not exists")
|
||||||
|
// }
|
||||||
|
|
||||||
log.Println(result)
|
// // 检查返回值中的 list 数组是否存在
|
||||||
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
// list := result.Get("list")
|
||||||
code := result.Get("code").Int()
|
// if !list.Exists() {
|
||||||
if code != 200 {
|
// t.Error("list is not exists")
|
||||||
t.Errorf("Invalid code value: %d", code)
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
// // 校验 list 数组中的每个条款 title 和 content 字段是否存在
|
||||||
msg := result.Get("msg").String()
|
// for _, item := range list.Array() {
|
||||||
if msg != "success" {
|
// title := item.Get("title")
|
||||||
t.Errorf(`Invalid msg value: "%s"`, msg)
|
// content := item.Get("content")
|
||||||
}
|
// if !title.Exists() || !content.Exists() {
|
||||||
|
// t.Error("title or content not exists")
|
||||||
// 检查返回值中的 data 字段是否存在,并且值是否符合预期
|
// log.Println(result)
|
||||||
token := result.Get("data.token").String()
|
// continue
|
||||||
if len(token) == 0 {
|
// }
|
||||||
t.Error("Missing token field")
|
// }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user