@@ -64,9 +64,10 @@ func TestNewLocalRateLimiter_Basic(t *testing.T) {
64
64
base := newBaseHTTPService (t , & hits )
65
65
66
66
rl := NewLocalRateLimiter (RateLimiterConfig {
67
- RequestsPerSecond : 5 ,
68
- Burst : 5 ,
69
- KeyFunc : func (* http.Request ) string { return "svc-basic" },
67
+ Requests : 5 ,
68
+ Window : time .Second ,
69
+ Burst : 5 ,
70
+ KeyFunc : func (* http.Request ) string { return "svc-basic" },
70
71
}, base )
71
72
72
73
resp , err := rl .Get (t .Context (), "/ok" , nil )
@@ -86,9 +87,10 @@ func TestLocalRateLimiter_EnforceLimit(t *testing.T) {
86
87
base := newBaseHTTPService (t , & hits )
87
88
88
89
rl := NewLocalRateLimiter (RateLimiterConfig {
89
- RequestsPerSecond : 1 ,
90
- Burst : 1 ,
91
- KeyFunc : func (* http.Request ) string { return "svc-limit" },
90
+ Requests : 1 ,
91
+ Window : time .Second ,
92
+ Burst : 1 ,
93
+ KeyFunc : func (* http.Request ) string { return "svc-limit" },
92
94
}, base )
93
95
94
96
resp , err := rl .Get (t .Context (), "/r1" , nil )
@@ -125,9 +127,10 @@ func TestLocalRateLimiter_FractionalRPS(t *testing.T) {
125
127
base := newBaseHTTPService (t , & hits )
126
128
127
129
rl := NewLocalRateLimiter (RateLimiterConfig {
128
- RequestsPerSecond : 0.5 ,
129
- Burst : 1 ,
130
- KeyFunc : func (* http.Request ) string { return "svc-frac" },
130
+ Requests : 0.5 ,
131
+ Window : time .Second ,
132
+ Burst : 1 ,
133
+ KeyFunc : func (* http.Request ) string { return "svc-frac" },
131
134
}, base )
132
135
133
136
resp , err := rl .Get (t .Context (), "/a" , nil )
@@ -164,9 +167,10 @@ func TestLocalRateLimiter_CustomKey_SharedBucket(t *testing.T) {
164
167
base := newBaseHTTPService (t , & hits )
165
168
166
169
rl := NewLocalRateLimiter (RateLimiterConfig {
167
- RequestsPerSecond : 1 ,
168
- Burst : 1 ,
169
- KeyFunc : func (* http.Request ) string { return "shared-key" },
170
+ Requests : 1 ,
171
+ Window : time .Second ,
172
+ Burst : 1 ,
173
+ KeyFunc : func (* http.Request ) string { return "shared-key" },
170
174
}, base )
171
175
172
176
resp , err := rl .Get (t .Context (), "/p1" , nil )
@@ -206,9 +210,10 @@ func TestLocalRateLimiter_Concurrency(t *testing.T) {
206
210
base := newBaseHTTPService (t , & hits )
207
211
208
212
rl := NewLocalRateLimiter (RateLimiterConfig {
209
- RequestsPerSecond : 1 ,
210
- Burst : 1 ,
211
- KeyFunc : func (* http.Request ) string { return "svc-conc" },
213
+ Requests : 1 ,
214
+ Window : time .Second ,
215
+ Burst : 1 ,
216
+ KeyFunc : func (* http.Request ) string { return "svc-conc" },
212
217
}, base )
213
218
214
219
const workers = 12
@@ -275,9 +280,10 @@ func TestLocalRateLimiter_NoMetrics(t *testing.T) {
275
280
base := newBaseHTTPService (t , & hits )
276
281
277
282
rl := NewLocalRateLimiter (RateLimiterConfig {
278
- RequestsPerSecond : 2 ,
279
- Burst : 2 ,
280
- KeyFunc : func (* http.Request ) string { return "svc-nometrics" },
283
+ Requests : 2 ,
284
+ Window : time .Second ,
285
+ Burst : 2 ,
286
+ KeyFunc : func (* http.Request ) string { return "svc-nometrics" },
281
287
}, base )
282
288
283
289
resp , err := rl .Get (t .Context (), "/m" , nil )
@@ -295,9 +301,10 @@ func TestLocalRateLimiter_RateLimitErrorFields(t *testing.T) {
295
301
base := newBaseHTTPService (t , & hits )
296
302
297
303
rl := NewLocalRateLimiter (RateLimiterConfig {
298
- RequestsPerSecond : 0 , // Always zero refill
299
- Burst : 1 ,
300
- KeyFunc : func (* http.Request ) string { return "svc-zero" },
304
+ Requests : 0 , // Always zero refill
305
+ Window : time .Second ,
306
+ Burst : 1 ,
307
+ KeyFunc : func (* http.Request ) string { return "svc-zero" },
301
308
}, base )
302
309
303
310
resp , err := rl .Get (t .Context (), "/z1" , nil )
@@ -330,16 +337,17 @@ func TestLocalRateLimiter_WrapperMethods_SuccessAndLimited(t *testing.T) {
330
337
331
338
// Success limiter: plenty of capacity
332
339
successRL := NewLocalRateLimiter (RateLimiterConfig {
333
- RequestsPerSecond : 100 ,
334
- Burst : 100 ,
335
- KeyFunc : func (* http.Request ) string { return "wrapper-allow" },
340
+ Requests : 100 ,
341
+ Window : time .Second ,
342
+ Burst : 100 ,
343
+ KeyFunc : func (* http.Request ) string { return "wrapper-allow" },
336
344
}, base )
337
345
338
346
// Deny limiter: zero capacity (covers error branch)
339
347
denyRL := NewLocalRateLimiter (RateLimiterConfig {
340
- RequestsPerSecond : 0 ,
341
- Burst : 0 ,
342
- KeyFunc : func (* http.Request ) string { return "wrapper-deny" },
348
+ Requests : 0 ,
349
+ Burst : 0 ,
350
+ KeyFunc : func (* http.Request ) string { return "wrapper-deny" },
343
351
}, base )
344
352
345
353
tests := []struct {
0 commit comments