(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestLimit_DifferentIPs(t *testing.T) { |
| 55 | handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 56 | w.WriteHeader(http.StatusOK) |
| 57 | }) |
| 58 | |
| 59 | limiter := NewRateLimiter() |
| 60 | middleware := limiter.Limit(handler) |
| 61 | |
| 62 | // Exhaust rate limit for first IP |
| 63 | for range serverRateLimitBurst + 5 { |
| 64 | req := httptest.NewRequest("GET", "/test", nil) |
| 65 | req.RemoteAddr = "192.168.1.1:1234" |
| 66 | w := httptest.NewRecorder() |
| 67 | middleware.ServeHTTP(w, req) |
| 68 | } |
| 69 | |
| 70 | // Request from different IP should still succeed |
| 71 | req := httptest.NewRequest("GET", "/test", nil) |
| 72 | req.RemoteAddr = "192.168.1.2:5678" |
| 73 | w := httptest.NewRecorder() |
| 74 | middleware.ServeHTTP(w, req) |
| 75 | |
| 76 | if w.Code != http.StatusOK { |
| 77 | t.Errorf("Request from different IP should succeed, got status %d", w.Code) |
| 78 | } |
| 79 | } |
nothing calls this directly
no test coverage detected