78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
|
package test
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"ifms/pkg/oss"
|
||
|
"net/http"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/gavv/httpexpect/v2"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"ifms/internal/config"
|
||
|
"ifms/internal/wirex"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
baseAPI = "/api/v1"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
app *gin.Engine
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
config.MustLoad("../configs/dev/", "server.toml")
|
||
|
|
||
|
_ = os.RemoveAll(config.C.Storage.DB.DSN)
|
||
|
ctx := context.Background()
|
||
|
injector, _, err := wirex.BuildInjector(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
if err := injector.M.Init(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
app = gin.New()
|
||
|
err = injector.M.RegisterRouters(ctx, app)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
// 阿里云 OSS 配置
|
||
|
config := oss.AliyunOssClientConfig{
|
||
|
Endpoint: "oss-cn-hangzhou.aliyuncs.com",
|
||
|
AccessKeyID: "LTAI5tMPLyvmGn44W6tEUzn9",
|
||
|
AccessKeySecret: "YgPynRZB73nl6JbnwZg0kqZhsEpA1v",
|
||
|
BucketName: "qkkj-ifms-test",
|
||
|
}
|
||
|
|
||
|
// 初始化阿里云 OSS 客户端
|
||
|
client, err := oss.NewAliyunOssClient(config)
|
||
|
if err != nil {
|
||
|
fmt.Println("Failed to create Aliyun OSS client:", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 设置全局 OSS 客户端
|
||
|
oss.SetGlobal(func() oss.IClient {
|
||
|
return client
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func tester(t *testing.T) *httpexpect.Expect {
|
||
|
return httpexpect.WithConfig(httpexpect.Config{
|
||
|
Client: &http.Client{
|
||
|
Transport: httpexpect.NewBinder(app),
|
||
|
Jar: httpexpect.NewCookieJar(),
|
||
|
},
|
||
|
Reporter: httpexpect.NewAssertReporter(t),
|
||
|
Printers: []httpexpect.Printer{
|
||
|
httpexpect.NewDebugPrinter(t, true),
|
||
|
},
|
||
|
})
|
||
|
}
|