Skip to content

Commit e1c0453

Browse files
committed
Add make target to start containerised test env.
1 parent accfea2 commit e1c0453

File tree

4 files changed

+57
-28
lines changed

4 files changed

+57
-28
lines changed

.github/CONTRIBUTING.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,39 @@ Set up test environments with ```make start```, tear down those environments wit
3131
This guide explains how to bootstrap and manage a test environment for Jedis using Docker Compose.
3232

3333
## Workflow Steps
34-
1. **Bring up the test environment** (examples provided below).
35-
2. **Run tests** (via IDE, Maven, etc.).
36-
3. **Destroy the test environment** using `docker compose down`.
34+
1. **Start the test environment** by running the following command (examples below).
35+
- For instance, to start the environment with Redis 8.0-M01, use `make start-test-env`.
36+
2. **Run tests** through your IDE, Maven, or other testing tools as needed.
37+
3. **Stop the test environment** by running the following command:
38+
- `make stop-test-env`
39+
- This will stop and tear down the Docker containers running the Redis service
3740

38-
### Important Note
39-
The default test environment uses the temporary work folder `./redis-env-work`.
40-
Some tests might leave Redis nodes in an inconsistent state, so this folder should be cleaned or removed before bootstrapping the environment again.
41+
# Start the Test Environment Using Docker
4142

43+
You can bootstrap the test environment for supported versions of Redis using the provided `make` targets.
4244

43-
## Bootstrap test env using Docker
44-
- **Redis 8.0-M01**
45+
## Option 1: Using `make` Targets
46+
To bring up the test environment for a specific Redis version (8.0-M01, 7.4.1, 7.2.6, or 6.2.16), use the following command:
47+
```bash
48+
make start-test-env version=8.0-M01 # Replace with desired version
4549
```
46-
rm -rf ./redis-env-work
50+
51+
## Option 2: Using docker compose commands directly
52+
Docker compose file can be found in `src/test/resources/env` folder.
53+
- **Redis 8.0-M01, 7.4.1, 7.2.6**
54+
```bash
55+
rm -rf /tmp/redis-env-work
4756
export REDIS_VERSION=8.0-M01
48-
docker compose --env-file src/test/resources/env/.env -f src/test/resources/env/docker-compose.yml up
49-
```
50-
- **Redis 7.4.1**
51-
```
52-
rm -rf ./redis-env-work
53-
export REDIS_VERSION=7.4.1
54-
docker compose --env-file src/test/resources/env/.env -f src/test/resources/env/docker-compose.yml up
55-
```
56-
- **Redis 7.2.6**
57-
```
58-
rm -rf ./redis-env-work
59-
export REDIS_VERSION=7.2.6
60-
docker compose --env-file src/test/resources/env/.env -f src/test/resources/env/docker-compose.yml up
57+
docker compose up
6158
```
6259
- **Redis 6.2.16**
63-
- **NOTE :** 6.2.16 uses a dedicated .env.v6.12.16 file, since some of the redis configuration settings are not supported in 6.2.16
64-
```
65-
rm -rf ./redis-env-work
66-
docker compose --env-file src/test/resources/env/.env.v6.12.16 -f src/test/resources/env/docker-compose.yml up
60+
- **NOTE:** Redis 6.2.16 uses a dedicated `.env.v6.2.16`.
61+
```bash
62+
rm -rf /tmp/redis-env-work
63+
docker compose --env-file .env.v6.2.16 up
6764
```
6865

66+
6967
# Some rules of Jedis source code
7068

7169
## Code Convention

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
PATH := ./redis-git/src:${PATH}
22

3+
# Supported test env versions
4+
SUPPORTED_TEST_ENV_VERSIONS := 8.0-M01 7.4.1 7.2.6 6.2.16
5+
DEFAULT_TEST_ENV_VERSION := 8.0-M01
6+
37
define REDIS1_CONF
48
daemonize yes
59
protected-mode no
@@ -559,5 +563,32 @@ system-setup:
559563
compile-module:
560564
gcc -shared -o /tmp/testmodule.so -fPIC src/test/resources/testmodule.c
561565

566+
# Start test environment with specific version using predefined docker compose setup
567+
568+
start-test-env:
569+
@if [ -z "$(version)" ]; then \
570+
version=$(arg); \
571+
if [ -z "$$version" ]; then \
572+
version="$(DEFAULT_TEST_ENV_VERSION)"; \
573+
fi; \
574+
fi; \
575+
if ! echo "$(SUPPORTED_TEST_ENV_VERSIONS)" | grep -qw "$$version"; then \
576+
echo "Error: Invalid version '$$version'. Supported versions are: $(SUPPORTED_TEST_ENV_VERSIONS)."; \
577+
exit 1; \
578+
fi; \
579+
env_file="src/test/resources/env/.env"; \
580+
if [ "$$version" = "6.2.16" ]; then \
581+
env_file="src/test/resources/env/.env.v6.2.16"; \
582+
fi; \
583+
rm -rf /tmp/redis-env-work; \
584+
export REDIS_VERSION=$$version && \
585+
docker compose --env-file $$env_file -f src/test/resources/env/docker-compose.yml up -d; \
586+
echo "Started test environment with Redis version $$version."
587+
588+
# Stop the test environment
589+
stop-test-env:
590+
docker compose -f src/test/resources/env/docker-compose.yml down; \
591+
rm -rf /tmp/redis-env-work; \
592+
echo "Stopped test environment and performed cleanup."
562593

563594
.PHONY: test

src/test/resources/env/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ REDIS_VERSION=8.0-M01
22
CLIENT_LIBS_TEST_IMAGE=redislabs/client-libs-test
33
REDIS_ENV_CONF_DIR=./
44
REDIS_MODULES_DIR=/tmp
5-
REDIS_ENV_WORK_DIR=./redis-env-work
5+
REDIS_ENV_WORK_DIR=/tmp/redis-env-work
66

77
ENABLE_MODULE_COMMAND_DIRECTIVE=--enable-module-command yes

src/test/resources/env/.env.v6.2.16

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ REDIS_VERSION=6.2.16
22
CLIENT_LIBS_TEST_IMAGE=redislabs/client-libs-test
33
REDIS_ENV_CONF_DIR=./
44
REDIS_MODULES_DIR=/tmp
5-
REDIS_ENV_WORK_DIR=./redis-env-work
5+
REDIS_ENV_WORK_DIR=/tmp/redis-env-work
66

77
#REMOVE UNSUPPORTED DIRECTIVE
88
ENABLE_MODULE_COMMAND_DIRECTIVE=

0 commit comments

Comments
 (0)