Skip to content

Commit

Permalink
add makefile to support testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pubalokta committed Jul 25, 2024
1 parent 2a8150b commit 1d6a131
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 23 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
#node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [18.x]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Start containers
run: docker-compose -f "docker-compose.yml" up -d --build

- name: Install node
uses: actions/setup-node@v4
with:
Expand All @@ -31,8 +29,20 @@ jobs:
- name: Install dependencies
run: npm install

- name: Run tests
run: npm run test
- name: Setup Standalone Tests
run: make test-standalone-setup

- name: Run Standalone tests
run: make test-standalone

- name: Teardown Standalone Tests
run: make test-standalone-teardown

- name: Setup Clustered Tests
run: make test-cluster-setup

- name: Run Clustered tests
run: make test-cluster

- name: Stop containers
run: docker-compose -f "docker-compose.yml" down
- name: Teardown Clustered Tests
run: make test-cluster-teardown
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
export CLUSTER_NO_TLS_VALIDATION=true

test-setup:
test-standalone-setup:
docker-compose up -d

test-teardown:
test-standalone-teardown:
docker-compose down

test-cluster-setup:
docker-compose -f docker-compose-cluster.yml up -d --wait
docker-compose -f docker-compose-cluster.yml up -d
timeout 60s sh -c 'until docker ps -a | grep limitd-redis-redis-cluster-create | grep -i exited; do echo "Waiting for cluster create container to finish..."; sleep 2; done'

test-cluster-teardown:
docker-compose -f docker-compose-cluster.yml down

test-run:
@echo "Running tests..."
npm run test

test-cluster:
npm run test-cluster
test-standalone:
npm run test-standalone
test: test-standalone test-cluster

test: test-standalone test-cluster
test-setup: test-standalone-setup test-cluster-setup
test-teardown: test-standalone-teardown test-cluster-teardown
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
`limitd-redis` is client for limits on top of `redis` using [Token Buckets](https://en.wikipedia.org/wiki/Token_bucket).
It's a fork from [LimitDB](https://github.com/limitd/limitdb).

## Table of Contents

- [Installation](#installation)
- [Configure](#configure)
- [Options available](#options-available)
- [Buckets](#buckets)
- [Ping](#ping)
- [Overrides](#overrides)
- [ERL (Elevated Rate Limits)](#erl-elevated-rate-limits)
- [Prerequisites](#prerequisites)
- [Introduction](#introduction)
- [Configuration](#configuration)
- [ERL Quota](#erl-quota)
- [Use of Redis hash tags](#use-of-redis-hash-tags)
- [Breaking changes from `Limitdb`](#breaking-changes-from-limitdb)
- [TAKE](#take)
- [TAKEELEVATED](#takeelevated)
- [PUT](#put)
- [Overriding Configuration at Runtime](#overriding-configuration-at-runtime)
- [Overriding Configuration at Runtime with ERL](#overriding-configuration-at-runtime-with-erl)
- [Testing](#testing)
- [Author](#author)
- [License](#license)

## Installation

```
Expand Down Expand Up @@ -345,6 +369,13 @@ const configOverride = {
}
```

## Testing

- Setup tests: `make test-setup`
- Run tests: `make test`
- Teardown tests: `make test-teardown`


## Author

[Auth0](auth0.com)
Expand Down
8 changes: 4 additions & 4 deletions docker-compose-cluster.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
redis-1:
image: 'a0us-docker.jfrog.io/redis:6'
image: 'redis:6'
healthcheck:
interval: "1s"
test: [ "CMD", "redis-cli", "-p", "16371", "ping", "|", "grep", "PONG" ]
Expand All @@ -9,7 +9,7 @@ services:
- ${PWD}/test-resources/redis-cluster/node-1/conf/redis.conf:/etc/redis/redis.conf
network_mode: host
redis-2:
image: 'a0us-docker.jfrog.io/redis:6'
image: 'redis:6'
healthcheck:
interval: "1s"
test: [ "CMD", "redis-cli", "-p", "16372", "ping", "|", "grep", "PONG" ]
Expand All @@ -18,7 +18,7 @@ services:
- ${PWD}/test-resources/redis-cluster/node-2/conf/redis.conf:/etc/redis/redis.conf
network_mode: host
redis-3:
image: 'a0us-docker.jfrog.io/redis:6'
image: 'redis:6'
healthcheck:
interval: "1s"
test: [ "CMD", "redis-cli", "-p", "16373", "ping", "|", "grep", "PONG" ]
Expand All @@ -27,7 +27,7 @@ services:
- ${PWD}/test-resources/redis-cluster/node-3/conf/redis.conf:/etc/redis/redis.conf
network_mode: host
redis-cluster-create:
image: 'a0us-docker.jfrog.io/redis:6'
image: 'redis:6'
command: '/usr/local/etc/redis/redis-cluster-create.sh'
depends_on:
redis-1:
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
"url": "http://github.com/auth0/limitd-redis.git"
},
"scripts": {
"test": "NODE_ENV=test nyc mocha --exit",
"test-standalone": "trap 'docker-compose -f docker-compose.yml down --remove-orphans -v' EXIT; docker-compose -f docker-compose.yml up -d && CLUSTERED_ENV=false NODE_ENV=test nyc mocha --exit",
"test-cluster": "trap 'docker-compose -f docker-compose-cluster.yml down --remove-orphans -v' EXIT; docker-compose -f docker-compose-cluster.yml up -d --wait && CLUSTERED_ENV=true NODE_ENV=test nyc mocha --exit"
"test-standalone": "CLUSTERED_ENV=false NODE_ENV=test nyc mocha --exit",
"test-cluster": "CLUSTERED_ENV=true NODE_ENV=test nyc mocha --exit"
},
"author": "Auth0",
"license": "MIT",
Expand Down

0 comments on commit 1d6a131

Please sign in to comment.