test(integration): 添加 Gateway 接口集成测试
- 添加 6 个卡 Gateway 接口测试(查询状态、流量、实名、获取链接、停机、复机) - 添加 7 个设备 Gateway 接口测试(查询信息、卡槽、限速、WiFi、切卡、重启、恢复出厂) - 每个接口测试包含成功场景和权限校验场景 - 更新测试环境初始化,添加 Gateway 客户端 mock 支持 - 所有 13 个接口测试通过
This commit is contained in:
@@ -3,6 +3,7 @@ package integ
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/gateway"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/auth"
|
||||
@@ -76,11 +78,14 @@ func NewIntegrationTestEnv(t *testing.T) *IntegrationTestEnv {
|
||||
logger, _ := zap.NewDevelopment()
|
||||
tokenManager := auth.NewTokenManager(rdb, 24*time.Hour, 7*24*time.Hour)
|
||||
|
||||
gatewayClient := createMockGatewayClient()
|
||||
|
||||
deps := &bootstrap.Dependencies{
|
||||
DB: tx,
|
||||
Redis: rdb,
|
||||
Logger: logger,
|
||||
TokenManager: tokenManager,
|
||||
DB: tx,
|
||||
Redis: rdb,
|
||||
Logger: logger,
|
||||
TokenManager: tokenManager,
|
||||
GatewayClient: gatewayClient,
|
||||
}
|
||||
|
||||
result, err := bootstrap.Bootstrap(deps)
|
||||
@@ -106,6 +111,22 @@ func NewIntegrationTestEnv(t *testing.T) *IntegrationTestEnv {
|
||||
return env
|
||||
}
|
||||
|
||||
func createMockGatewayClient() *gateway.Client {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
resp := gateway.GatewayResponse{
|
||||
Code: 200,
|
||||
Msg: "success",
|
||||
TraceID: "test-trace-id",
|
||||
Data: json.RawMessage(`{}`),
|
||||
}
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
}))
|
||||
|
||||
client := gateway.NewClient(server.URL, "test-app-id", "test-app-secret")
|
||||
return client
|
||||
}
|
||||
|
||||
// AsSuperAdmin 设置当前请求使用超级管理员身份
|
||||
// 返回 IntegrationTestEnv 以支持链式调用
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user