Documentation
¶
Index ¶
- Variables
- func AssertJSON(t *testing.T, w *httptest.ResponseRecorder, expected map[string]any)
- func AssertStatus(t *testing.T, w *httptest.ResponseRecorder, expected int)
- func CleanupDB(db *gorm.DB)
- func ParseResponse(t *testing.T, w *httptest.ResponseRecorder, v any)
- func SetupTestRouter() *gin.Engine
- func TestConfig() *config.Config
- type APITestClient
- func (c *APITestClient) DELETE(path string) *httptest.ResponseRecorder
- func (c *APITestClient) GET(path string) *httptest.ResponseRecorder
- func (c *APITestClient) POST(path string, body any) *httptest.ResponseRecorder
- func (c *APITestClient) PUT(path string, body any) *httptest.ResponseRecorder
- func (c *APITestClient) Request(method, path string, body any) *httptest.ResponseRecorder
- func (c *APITestClient) SetAuth(token string) *APITestClient
- type MockFactory
- func (f *MockFactory) CreateAdminUser(overrides ...func(*model.User)) *model.User
- func (f *MockFactory) CreateAuthorizedKey(overrides ...func(*model.AuthorizedKey)) *model.AuthorizedKey
- func (f *MockFactory) CreateCoupon(overrides ...func(*model.Coupon)) *model.Coupon
- func (f *MockFactory) CreateNode(overrides ...func(*model.Node)) *model.Node
- func (f *MockFactory) CreateNodeProtocol(nodeID uint, overrides ...func(*model.NodeProtocol)) *model.NodeProtocol
- func (f *MockFactory) CreateOrder(userID, planID uint, overrides ...func(*model.Order)) *model.Order
- func (f *MockFactory) CreatePlan(overrides ...func(*model.Plan)) *model.Plan
- func (f *MockFactory) CreateSubscriptionGroup(overrides ...func(*model.SubscriptionGroup)) *model.SubscriptionGroup
- func (f *MockFactory) CreateUser(overrides ...func(*model.User)) *model.User
- func (f *MockFactory) GenerateJWTToken(userID uint, isAdmin bool) string
- func (f *MockFactory) HashPassword(password string) string
- type TestDB
Constants ¶
This section is empty.
Variables ¶
View Source
var Factory = &MockFactory{}
Functions ¶
func AssertJSON ¶
AssertJSON 断言 JSON 响应
func AssertStatus ¶
func AssertStatus(t *testing.T, w *httptest.ResponseRecorder, expected int)
AssertStatus 断言状态码
func ParseResponse ¶
func ParseResponse(t *testing.T, w *httptest.ResponseRecorder, v any)
ParseResponse 解析响应
Types ¶
type APITestClient ¶
APITestClient API 测试客户端
func NewAPITestClient ¶
func NewAPITestClient(t *testing.T, router *gin.Engine) *APITestClient
NewAPITestClient 创建 API 测试客户端
func (*APITestClient) DELETE ¶
func (c *APITestClient) DELETE(path string) *httptest.ResponseRecorder
DELETE 发送 DELETE 请求
func (*APITestClient) GET ¶
func (c *APITestClient) GET(path string) *httptest.ResponseRecorder
GET 发送 GET 请求
func (*APITestClient) POST ¶
func (c *APITestClient) POST(path string, body any) *httptest.ResponseRecorder
POST 发送 POST 请求
func (*APITestClient) PUT ¶
func (c *APITestClient) PUT(path string, body any) *httptest.ResponseRecorder
PUT 发送 PUT 请求
func (*APITestClient) Request ¶
func (c *APITestClient) Request(method, path string, body any) *httptest.ResponseRecorder
Request 发送请求
func (*APITestClient) SetAuth ¶
func (c *APITestClient) SetAuth(token string) *APITestClient
SetAuth 设置认证 Token
type MockFactory ¶
type MockFactory struct{}
MockFactory 模拟数据工厂
func (*MockFactory) CreateAdminUser ¶
func (f *MockFactory) CreateAdminUser(overrides ...func(*model.User)) *model.User
CreateAdminUser 创建管理员用户
func (*MockFactory) CreateAuthorizedKey ¶
func (f *MockFactory) CreateAuthorizedKey(overrides ...func(*model.AuthorizedKey)) *model.AuthorizedKey
CreateAuthorizedKey 创建授权密钥
func (*MockFactory) CreateCoupon ¶
func (f *MockFactory) CreateCoupon(overrides ...func(*model.Coupon)) *model.Coupon
CreateCoupon 创建优惠券
func (*MockFactory) CreateNode ¶
func (f *MockFactory) CreateNode(overrides ...func(*model.Node)) *model.Node
CreateNode 创建测试节点
func (*MockFactory) CreateNodeProtocol ¶
func (f *MockFactory) CreateNodeProtocol(nodeID uint, overrides ...func(*model.NodeProtocol)) *model.NodeProtocol
CreateNodeProtocol 创建节点协议配置
func (*MockFactory) CreateOrder ¶
func (f *MockFactory) CreateOrder(userID, planID uint, overrides ...func(*model.Order)) *model.Order
CreateOrder 创建测试订单
func (*MockFactory) CreatePlan ¶
func (f *MockFactory) CreatePlan(overrides ...func(*model.Plan)) *model.Plan
CreatePlan 创建测试套餐
func (*MockFactory) CreateSubscriptionGroup ¶
func (f *MockFactory) CreateSubscriptionGroup(overrides ...func(*model.SubscriptionGroup)) *model.SubscriptionGroup
CreateSubscriptionGroup 创建订阅分组
func (*MockFactory) CreateUser ¶
func (f *MockFactory) CreateUser(overrides ...func(*model.User)) *model.User
CreateUser 创建测试用户
func (*MockFactory) GenerateJWTToken ¶
func (f *MockFactory) GenerateJWTToken(userID uint, isAdmin bool) string
GenerateJWTToken 生成测试 JWT Token
func (*MockFactory) HashPassword ¶
func (f *MockFactory) HashPassword(password string) string
HashPassword 哈希密码
type TestDB ¶
TestDB 测试数据库包装器
func (*TestDB) CloseWithError ¶
CloseWithError closes the test database and returns cleanup failures.
Click to show internal directories.
Click to hide internal directories.