Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
feat: implement docker-compose and adjust tests workflow to use docker
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Mar 5, 2021
1 parent 98de6ee commit 427e811
Show file tree
Hide file tree
Showing 7 changed files with 8,825 additions and 8,837 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ jobs:
matrix:
node-version: [10, 12, 14]
steps:
- name: Initiate docker containers
run: docker-compose -f docker-compose.yml up -d
- name: Check running containers
run: docker ps -a
- name: Check docker logs
run: docker logs redis
- uses: actions/checkout@v2
- name: Setup NodeJS v${{ matrix.node-version }}
uses: actions/setup-node@v1
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
redis:
image: redis
container_name: redis
ports:
- '6379:6379'
17 changes: 15 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"devDependencies": {
"@commitlint/cli": "^12.0.0",
"@commitlint/config-conventional": "^12.0.0",
"@golevelup/ts-jest": "^0.3.1",
"@nestjs/cli": "^7.5.5",
"@nestjs/common": "^7.6.13",
"@nestjs/core": "^7.6.13",
Expand Down
12 changes: 9 additions & 3 deletions src/throttler-storage-redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import { ThrottlerStorageRedis } from './throttler-storage-redis.interface';
export class ThrottlerStorageRedisService implements ThrottlerStorageRedis {
redis: Redis.Redis;

constructor(options?: Redis.RedisOptions) {
this.redis = new Redis(options);
constructor(redis?: Redis.Redis);
constructor(options?: Redis.RedisOptions);
constructor(redisOrOptions?: Redis.Redis | Redis.RedisOptions) {
if (redisOrOptions instanceof Redis) {
this.redis = redisOrOptions;
} else {
this.redis = new Redis(redisOrOptions);
}
}

async getRecord(key: string): Promise<number[]> {
Expand All @@ -16,6 +22,6 @@ export class ThrottlerStorageRedisService implements ThrottlerStorageRedis {
}

async addRecord(key: string, ttl: number): Promise<void> {
this.redis.set(`${key}:${Date.now() + ttl * 1000}`, ttl, 'EX', ttl);
await this.redis.set(`${key}:${Date.now() + ttl * 1000}`, ttl, 'EX', ttl);
}
}
3 changes: 2 additions & 1 deletion test/app/controllers/controller.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Module } from '@nestjs/common';
import { ThrottlerModule } from '@nestjs/throttler';
import { ThrottlerModule, ThrottlerStorageService } from '@nestjs/throttler';
import { AppService } from '../app.service';
import { AppController } from './app.controller';
import { DefaultController } from './default.controller';
Expand All @@ -11,6 +11,7 @@ import { LimitController } from './limit.controller';
limit: 5,
ttl: 60,
ignoreUserAgents: [/throttler-test/g],
storage: new ThrottlerStorageService(),
}),
],
controllers: [AppController, DefaultController, LimitController],
Expand Down
Loading

0 comments on commit 427e811

Please sign in to comment.