package test import ( "fmt" "fusenapi/server/upload/internal/types" "fusenapi/utils/format" fstests "fusenapi/utils/fstests" "io/ioutil" "log" "testing" "github.com/474420502/requests" "github.com/tidwall/gjson" ) func TestCasePersonalization(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-frontend", cnf.Host, cnf.Port)) data, err := ioutil.ReadFile("./fusen.webp") if err != nil { t.Error(err) return } req := types.RequestUploadFileFrontend{ 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 { t.Error(err) } if resp.GetStatusCode() != 200 { t.Error("put failed") } } func TestCaseRenderMegreF(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-frontend", cnf.Host, cnf.Port)) data, err := ioutil.ReadFile("./fusen.webp") if err != nil { t.Error(err) return } req := types.RequestUploadFileFrontend{ FileName: "fusen.webp", FileType: "image", FileSize: int64(len(data)), Category: string(format.TCategoryRenderMegre), } 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 { t.Error(err) } if resp.GetStatusCode() != 200 { t.Error("put failed") } }