Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
@@ -2,36 +2,38 @@ package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/server/home-user-auth/test"
|
||||
homeuserauthtest "fusenapi/server/home-user-auth/test"
|
||||
"fusenapi/server/upload/internal/config"
|
||||
"fusenapi/server/upload/internal/handler"
|
||||
"fusenapi/server/upload/internal/svc"
|
||||
"fusenapi/utils/fstests"
|
||||
"log"
|
||||
"runtime"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var env = "test"
|
||||
|
||||
var testConfigFile = "upload.yaml"
|
||||
var cnf config.Config
|
||||
var userServer *rest.Server
|
||||
var gserver *rest.Server
|
||||
|
||||
var userver, gserver *rest.Server
|
||||
|
||||
func init() {
|
||||
log.SetFlags(log.Llongfile)
|
||||
userServer = test.GetTestServer()
|
||||
userver = homeuserauthtest.GetTestServer()
|
||||
gserver = GetTestServer()
|
||||
}
|
||||
|
||||
func GetTestServer() *rest.Server {
|
||||
|
||||
conf.MustLoad(fstests.GetEtcYamlPathAuto(fstests.GetCurrentServiceName()+".yaml"), &cnf)
|
||||
|
||||
// log.Println(fstests.GetEtcYamlPathAuto())
|
||||
conf.MustLoad(fstests.GetEtcYamlPathAuto(), &cnf)
|
||||
server := rest.MustNewServer(cnf.RestConf)
|
||||
defer server.Stop()
|
||||
runtime.SetFinalizer(server, func(server *rest.Server) {
|
||||
if server != nil {
|
||||
server.Stop()
|
||||
}
|
||||
})
|
||||
|
||||
ctx := svc.NewServiceContext(cnf)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestCaseUploadfileFrontend(t *testing.T) {
|
||||
var result gjson.Result
|
||||
|
||||
// 获取 session,并携带 JWT token
|
||||
ses := fstests.GetSessionWithUserToken(t, userServer, cnf.Host, cnf.Port)
|
||||
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")
|
||||
@@ -27,7 +27,7 @@ func TestCaseUploadfileFrontend(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
req := types.RequestUploadFile{
|
||||
req := types.RequestUploadFileFrontend{
|
||||
FileName: "fusen.webp", FileType: "image", FileSize: int64(len(data)),
|
||||
Category: "personalization",
|
||||
}
|
||||
@@ -55,13 +55,14 @@ func TestCaseUploadfileFrontend(t *testing.T) {
|
||||
uri := result.Get("data.upload_url").String()
|
||||
|
||||
tpUpload := requests.NewSession().Put(uri)
|
||||
|
||||
tpUpload.SetBodyStream(data)
|
||||
|
||||
resp, err = tpUpload.Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
log.Println(resp.Json())
|
||||
if resp.GetStatusCode() != 200 {
|
||||
t.Error("put failed")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user