Files
gochat/internal/handler/api/v1/test_helpers_auth.go
T
2026-06-04 15:44:48 +08:00

26 lines
637 B
Go

package v1
import (
"strconv"
"github.com/gin-gonic/gin"
)
// handlerTestResponse is a shared response struct for unmarshalling handler test JSON output.
type handlerTestResponse struct {
Success bool `json:"success"`
Data interface{} `json:"data"`
}
// mockAuthMiddleware simulates auth middleware for edge-case tests.
// Sets user_id=1 and extracts account_id from URL param.
func mockAuthMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Set("user_id", uint(1))
if accID, err := strconv.ParseUint(c.Param("account_id"), 10, 32); err == nil {
c.Set("account_id", uint(accID))
}
c.Next()
}
}