2023-07-07 06:49:02 +00:00
|
|
|
|
package test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"fusenapi/utils/format"
|
|
|
|
|
fstests "fusenapi/utils/fstests"
|
2023-07-07 09:49:12 +00:00
|
|
|
|
"log"
|
|
|
|
|
"os"
|
2023-07-07 06:49:02 +00:00
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/474420502/requests"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCaseRenderMegre(t *testing.T) {
|
|
|
|
|
var err error
|
|
|
|
|
var resp *requests.Response
|
|
|
|
|
var result gjson.Result
|
|
|
|
|
|
|
|
|
|
// 获取 session,并携带 JWT token
|
|
|
|
|
ses := fstests.GetSessionWithUserToken(t, userver, cnf.Host, cnf.Port)
|
|
|
|
|
tp := ses.Post(fmt.Sprintf("http://%s:%d/upload/upload-file-backend", cnf.Host, cnf.Port))
|
|
|
|
|
|
|
|
|
|
mp := tp.CreateBodyMultipart()
|
2023-07-07 09:49:12 +00:00
|
|
|
|
f, err := os.Open("./fusen.webp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = mp.AddFieldFile("file", f.Name(), f)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
err = mp.AddField("file_type", "image")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
err = mp.AddField("category", string(format.TCategoryRenderMegre))
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2023-07-07 06:49:02 +00:00
|
|
|
|
tp.SetBodyFormData(mp)
|
|
|
|
|
|
|
|
|
|
// 向服务器发送 GET 请求,获取用户基本信息
|
|
|
|
|
resp, err = tp.TestExecute(gserver)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = resp.Json()
|
|
|
|
|
if result.Get("code").Int() != 200 {
|
|
|
|
|
t.Error("code != 200")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !result.Get("data").Exists() {
|
|
|
|
|
t.Error("data not exists")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !result.Get("data.upload_url").Exists() {
|
|
|
|
|
t.Error("upload_url not exists")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if resp.GetStatusCode() != 200 {
|
|
|
|
|
t.Error("put failed")
|
|
|
|
|
}
|
|
|
|
|
}
|