MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestRateLimitMiddleware

Function TestRateLimitMiddleware

api/middleware/auth_test.go:896–945  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

894}
895
896func TestRateLimitMiddleware(t *testing.T) {
897 gin.SetMode(gin.TestMode)
898
899 t.Run("Rate limiting disabled when config is nil", func(t *testing.T) {
900 conf := &config.Configuration{
901 RateLimit: config.RateLimitConfig{
902 RequestsPerSecond: nil,
903 Burst: nil,
904 },
905 }
906
907 router := gin.New()
908 router.Use(RateLimitMiddleware(conf))
909 router.GET("/test", func(c *gin.Context) {
910 c.Status(http.StatusOK)
911 })
912
913 w := httptest.NewRecorder()
914 req, _ := http.NewRequest("GET", "/test", nil)
915 router.ServeHTTP(w, req)
916
917 assert.Equal(t, http.StatusOK, w.Code)
918 })
919
920 t.Run("Rate limiting enabled", func(t *testing.T) {
921 rps := 100.0
922 burst := 10
923 cleanup := 60
924
925 conf := &config.Configuration{
926 RateLimit: config.RateLimitConfig{
927 RequestsPerSecond: &rps,
928 Burst: &burst,
929 CleanupIntervalSec: &cleanup,
930 },
931 }
932
933 router := gin.New()
934 router.Use(RateLimitMiddleware(conf))
935 router.GET("/test", func(c *gin.Context) {
936 c.Status(http.StatusOK)
937 })
938
939 w := httptest.NewRecorder()
940 req, _ := http.NewRequest("GET", "/test", nil)
941 router.ServeHTTP(w, req)
942
943 assert.Equal(t, http.StatusOK, w.Code)
944 })
945}
946
947func TestInjectAPIKeyToMetadata(t *testing.T) {
948 gin.SetMode(gin.TestMode)

Callers

nothing calls this directly

Calls 1

RateLimitMiddlewareFunction · 0.85

Tested by

no test coverage detected