Skip to content

Commit 35aa05b

Browse files
committed
CLDSRV-810: Add config tests for tokenBucketBufferSize and tokenBucketRefillThreshold
1 parent cb396dc commit 35aa05b

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

tests/unit/api/apiUtils/rateLimit/config.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,120 @@ describe('parseRateLimitConfig', () => {
187187
});
188188
});
189189

190+
describe('tokenBucketBufferSize validation', () => {
191+
it('should use default tokenBucketBufferSize when not specified', () => {
192+
const config = {
193+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
194+
};
195+
196+
const result = parseRateLimitConfig(config, 1);
197+
assert.strictEqual(result.tokenBucketBufferSize, 50);
198+
});
199+
200+
it('should accept custom tokenBucketBufferSize', () => {
201+
const config = {
202+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
203+
tokenBucketBufferSize: 100,
204+
};
205+
206+
const result = parseRateLimitConfig(config, 1);
207+
assert.strictEqual(result.tokenBucketBufferSize, 100);
208+
});
209+
210+
it('should throw if tokenBucketBufferSize is not a positive integer', () => {
211+
const config = {
212+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
213+
tokenBucketBufferSize: -10,
214+
};
215+
216+
assert.throws(
217+
() => parseRateLimitConfig(config, 1),
218+
/rateLimiting.tokenBucketBufferSize must be a positive integer/
219+
);
220+
});
221+
222+
it('should throw if tokenBucketBufferSize is zero', () => {
223+
const config = {
224+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
225+
tokenBucketBufferSize: 0,
226+
};
227+
228+
assert.throws(
229+
() => parseRateLimitConfig(config, 1),
230+
/rateLimiting.tokenBucketBufferSize must be a positive integer/
231+
);
232+
});
233+
234+
it('should throw if tokenBucketBufferSize is not an integer', () => {
235+
const config = {
236+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
237+
tokenBucketBufferSize: 50.5,
238+
};
239+
240+
assert.throws(
241+
() => parseRateLimitConfig(config, 1),
242+
/rateLimiting.tokenBucketBufferSize must be a positive integer/
243+
);
244+
});
245+
});
246+
247+
describe('tokenBucketRefillThreshold validation', () => {
248+
it('should use default tokenBucketRefillThreshold when not specified', () => {
249+
const config = {
250+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
251+
};
252+
253+
const result = parseRateLimitConfig(config, 1);
254+
assert.strictEqual(result.tokenBucketRefillThreshold, 20);
255+
});
256+
257+
it('should accept custom tokenBucketRefillThreshold', () => {
258+
const config = {
259+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
260+
tokenBucketRefillThreshold: 30,
261+
};
262+
263+
const result = parseRateLimitConfig(config, 1);
264+
assert.strictEqual(result.tokenBucketRefillThreshold, 30);
265+
});
266+
267+
it('should throw if tokenBucketRefillThreshold is not a positive integer', () => {
268+
const config = {
269+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
270+
tokenBucketRefillThreshold: -5,
271+
};
272+
273+
assert.throws(
274+
() => parseRateLimitConfig(config, 1),
275+
/rateLimiting.tokenBucketRefillThreshold must be a positive integer/
276+
);
277+
});
278+
279+
it('should throw if tokenBucketRefillThreshold is zero', () => {
280+
const config = {
281+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
282+
tokenBucketRefillThreshold: 0,
283+
};
284+
285+
assert.throws(
286+
() => parseRateLimitConfig(config, 1),
287+
/rateLimiting.tokenBucketRefillThreshold must be a positive integer/
288+
);
289+
});
290+
291+
it('should throw if tokenBucketRefillThreshold is not an integer', () => {
292+
const config = {
293+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
294+
tokenBucketRefillThreshold: 20.5,
295+
};
296+
297+
assert.throws(
298+
() => parseRateLimitConfig(config, 1),
299+
/rateLimiting.tokenBucketRefillThreshold must be a positive integer/
300+
);
301+
});
302+
});
303+
190304
describe('bucket validation', () => {
191305
it('should throw if bucket is not an object', () => {
192306
const config = {

0 commit comments

Comments
 (0)