2023-07-05 11:00:33 +00:00
|
|
|
|
package test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"fusenapi/server/upload/internal/types"
|
|
|
|
|
fstests "fusenapi/utils/fstests"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"log"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/474420502/requests"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
)
|
|
|
|
|
|
2023-07-07 06:49:02 +00:00
|
|
|
|
func TestCasePersonalization(t *testing.T) {
|
2023-07-05 11:00:33 +00:00
|
|
|
|
var err error
|
|
|
|
|
var resp *requests.Response
|
|
|
|
|
var result gjson.Result
|
|
|
|
|
|
|
|
|
|
// 获取 session,并携带 JWT token
|
2023-07-06 10:23:43 +00:00
|
|
|
|
ses := fstests.GetSessionWithUserToken(t, userver, cnf.Host, cnf.Port)
|
2023-07-05 11:00:33 +00:00
|
|
|
|
tp := ses.Post(fmt.Sprintf("http://%s:%d/upload/upload-file-frontend", cnf.Host, cnf.Port))
|
|
|
|
|
|
|
|
|
|
data, err := ioutil.ReadFile("./fusen.webp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 10:23:43 +00:00
|
|
|
|
req := types.RequestUploadFileFrontend{
|
2023-07-05 11:00:33 +00:00
|
|
|
|
FileName: "fusen.webp", FileType: "image", FileSize: int64(len(data)),
|
|
|
|
|
Category: "personalization",
|
|
|
|
|
}
|
|
|
|
|
tp.SetBodyJson(req)
|
|
|
|
|
// 向服务器发送 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")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println(result)
|
|
|
|
|
uri := result.Get("data.upload_url").String()
|
|
|
|
|
|
|
|
|
|
tpUpload := requests.NewSession().Put(uri)
|
|
|
|
|
tpUpload.SetBodyStream(data)
|
|
|
|
|
|
|
|
|
|
resp, err = tpUpload.Execute()
|
|
|
|
|
if err != nil {
|
2023-07-06 10:23:43 +00:00
|
|
|
|
t.Error(err)
|
2023-07-05 11:00:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 10:23:43 +00:00
|
|
|
|
if resp.GetStatusCode() != 200 {
|
|
|
|
|
t.Error("put failed")
|
|
|
|
|
}
|
2023-07-05 11:00:33 +00:00
|
|
|
|
}
|