This commit is contained in:
eson
2023-07-05 19:00:33 +08:00
parent c6005983f8
commit 1c74c0ea4b
24 changed files with 196 additions and 131 deletions

View File

@@ -2,7 +2,7 @@ package test
import (
"fmt"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"log"
"testing"
)

View File

@@ -1,8 +1,8 @@
package logic
package test
import (
"fmt"
fstests "fusenapi/utils/tests"
"fusenapi/utils/fstests"
"testing"

View File

@@ -1,17 +1,19 @@
package logic
package test
import (
"fmt"
"fusenapi/server/home-user-auth/internal/config"
"fusenapi/server/home-user-auth/internal/handler"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/utils/fstests"
"log"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var testConfigFile = "../etc/home-user-auth.yaml"
var testConfigFile = "home-user-auth"
var cnf config.Config
var gserver *rest.Server
@@ -22,7 +24,7 @@ func init() {
func GetTestServer() *rest.Server {
conf.MustLoad(testConfigFile, &cnf)
conf.MustLoad(fstests.GetEtcYamlPathAuto(testConfigFile), &cnf)
server := rest.MustNewServer(cnf.RestConf)
defer server.Stop()

View File

@@ -1,9 +1,9 @@
package logic
package test
import (
"fmt"
"fusenapi/server/home-user-auth/internal/types"
fstests "fusenapi/utils/tests"
"fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -1,8 +1,8 @@
package logic
package test
import (
"fmt"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -1,8 +1,8 @@
package logic
package test
import (
"fmt"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -1,9 +1,9 @@
package logic
package test
import (
"fmt"
"fusenapi/server/home-user-auth/internal/types"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -1,8 +1,8 @@
package logic
package test
import (
"fmt"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -1,8 +1,8 @@
package logic
package test
import (
"fmt"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -1,9 +1,9 @@
package logic
package test
import (
"fmt"
"fusenapi/server/home-user-auth/internal/types"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -1,10 +1,10 @@
package logic
package test
import (
"encoding/json"
"fmt"
"fusenapi/server/home-user-auth/internal/types"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -1,8 +1,8 @@
package logic
package test
import (
"fmt"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"

View File

@@ -9,10 +9,11 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"gorm.io/gorm"
"strconv"
"strings"
"gorm.io/gorm"
"context"
"fusenapi/server/product/internal/svc"
@@ -68,7 +69,7 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
}
}
//尺寸列表[这里要处理数据中的title]
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByStatus(l.ctx, int64(constants.STATUS_ON), 1, "id,title,capacity,cover,sort,parts_can_deleted")
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByStatus(l.ctx, int64(constants.FAQ_STATUS_ON), 1, "id,title,capacity,cover,sort,parts_can_deleted")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product size list")

View File

@@ -0,0 +1,41 @@
package test
import (
"fmt"
"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"
"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
func init() {
log.SetFlags(log.Llongfile)
userServer = test.GetTestServer()
gserver = GetTestServer()
}
func GetTestServer() *rest.Server {
conf.MustLoad(fstests.GetEtcYamlPathAuto(fstests.GetCurrentServiceName()+".yaml"), &cnf)
server := rest.MustNewServer(cnf.RestConf)
defer server.Stop()
ctx := svc.NewServiceContext(cnf)
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", cnf.Host, cnf.Port)
return server
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,67 @@
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"
)
func TestCaseUploadfileFrontend(t *testing.T) {
var err error
var resp *requests.Response
var result gjson.Result
// 获取 session并携带 JWT token
ses := fstests.GetSessionWithUserToken(t, userServer, 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.RequestUploadFile{
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 {
panic(err)
}
log.Println(resp.Json())
}

View File

@@ -3,7 +3,7 @@ package logic
import (
"fmt"
"fusenapi/constants"
fstests "fusenapi/utils/tests"
fstests "fusenapi/utils/fstests"
"testing"
"github.com/474420502/requests"