Skip to content

Commit

Permalink
adds some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maeddin committed Jul 28, 2024
1 parent 98d4472 commit ce50226
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/token_bucket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ void main() {
});
});

test('Bucket respects storage value', () {
final storage = MockTokenBucketStorage();
final tokenBucketState =
TokenBucketState(tokens: 3, lastRefillTime: clock.now());
when(() => storage.get()).thenReturn(tokenBucketState);
final bucket = TokenBucket(
size: 15,
refillInterval: const Duration(seconds: 1),
refillAmount: 10,
storage: storage,
);
expect(bucket.availableTokens, tokenBucketState.tokens);
});

test('Async bucket respects storage value', () {
final storage = MockTokenBucketStorage();
final tokenBucketState =
TokenBucketState(tokens: 3, lastRefillTime: clock.now());
when(() => storage.get()).thenReturn(tokenBucketState);
final bucket = AsyncTokenBucket(
size: 15,
refillInterval: const Duration(seconds: 1),
refillAmount: 10,
storage: storage,
);
expect(bucket.availableTokens, completion(tokenBucketState.tokens));
});

test('Consuming invalid amounts', () {
const size = 15;
const refillAmount = 10;
Expand Down

0 comments on commit ce50226

Please sign in to comment.