优化结构

This commit is contained in:
Yvan 2026-08-22 14:12:22 +08:00
parent 9dd62c9fb6
commit ca52de5db0
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package middleware
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
func TestSecurityRateLimitAllowsRequestsWhenSecurityServiceIsUnset(t *testing.T) {
gin.SetMode(gin.TestMode)
engine := gin.New()
engine.Use(SecurityRateLimit(nil))
engine.POST("/base/login", func(c *gin.Context) { c.Status(http.StatusNoContent) })
response := httptest.NewRecorder()
engine.ServeHTTP(response, httptest.NewRequest(http.MethodPost, "/base/login", nil))
if response.Code != http.StatusNoContent {
t.Fatalf("status = %d, want %d", response.Code, http.StatusNoContent)
}
}