Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,39 @@ jobs:
MYSQL_PASSWORD: userpassword
ports:
- "3306:3306"
# volumes:
# - mysql_data:/var/lib/mysql
# Required for MySQL 8.0+ compatibility with Go MySQL drivers
command: --default-authentication-plugin=mysql_native_password
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Install Dependenies
- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends ca-certificates postgresql-client

- name: Checkout code
uses: actions/checkout@v3

- name: Add postgres tables
run: PGPASSWORD=testPass psql -U testUser -h localhost -p 5432 -d testDB -c 'CREATE TABLE entries (id BIGSERIAL PRIMARY KEY, amount REAL, user_id VARCHAR(6), entry_date DATE, timestamp TIMESTAMP)';

- name: Add mysql tables
run: mysql -h localhost -P 3306 -u root -p mydb --protocol=TCP --password=rootpassword -e 'CREATE TABLE entries (id BIGINT PRIMARY KEY, amount REAL, user_id VARCHAR(6), entry_date DATE, timestamp TIMESTAMP)'

- name: Build binary
run: CGO_ENABLED=0 go build -o server.bin -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'" ./cmd/*.go

- name: Run binary server
run: ./server.bin --config config.test_pg.toml --sql-directory=sql/pg &

- name: Run tests
run: sleep 5 && go test ./client -v -covermode=count

- name: Run binary server
run: ./server.bin --config config.test_mysql.toml --sql-directory=sql/mysql &

- name: Run tests
run: sleep 5 && go test ./client -v -covermode=count

- name: Run PostgreSQL tests
run: |
./server.bin --config config.test_pg.toml --sql-directory=sql/pg &
sleep 5
go test ./client -v -covermode=count
pkill -f server.bin || true

- name: Run MySQL tests
run: |
./server.bin --config config.test_mysql.toml --sql-directory=sql/mysql &
sleep 5
go test ./client -v -covermode=count
pkill -f server.bin || true
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ dist: build
test:
go test ./... -v -p 1

# Local testing targets using unified test script
.PHONY: test-local
test-local:
./scripts/test.sh all

.PHONY: test-setup
test-setup:
./scripts/test.sh setup

.PHONY: test-run
test-run:
./scripts/test.sh run

.PHONY: test-cleanup
test-cleanup:
./scripts/test.sh cleanup

.PHONY: test-postgres
test-postgres:
./scripts/test.sh run --postgres

.PHONY: test-mysql
test-mysql:
./scripts/test.sh run --mysql

# Use goreleaser to do a dry run producing local builds.
.PHONY: release-dry
release-dry:
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,38 @@ dungbeetle --config /path/to/config.toml --sql-directory /path/to/your/sql/queri

Starting the server runs a set of workers listening on a default job queue. It also starts an HTTP service on `http://127.0.0.1:6060` which is the control interface. It's possible to run the server without the HTTP interface by passing the `--worker-only` flag.

## Local Testing

Run tests locally using Docker and Docker Compose.

### Quick Start

```bash
# Run all tests
make test-local

# Test specific databases
make test-postgres
make test-mysql
```

### Test Commands

| Command | Description |
|---------|-------------|
| `make test-local` | Complete test cycle |
| `make test-setup` | Start test services |
| `make test-run` | Run tests |
| `make test-cleanup` | Stop services |
| `make test-postgres` | PostgreSQL tests only |
| `make test-mysql` | MySQL tests only |

### Prerequisites

- Docker
- Docker Compose
- Go 1.21+


### Usage
| Method | URI | |
Expand Down
55 changes: 55 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: '3.8'

services:
redis:
image: redis:7-alpine
container_name: dungbeetle-test-redis
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
networks:
- dungbeetle-test

postgres:
image: postgres:15-alpine
container_name: dungbeetle-test-postgres
environment:
POSTGRES_PASSWORD: testPass
POSTGRES_USER: testUser
POSTGRES_DB: testDB
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U testUser -d testDB"]
interval: 10s
timeout: 5s
retries: 5
networks:
- dungbeetle-test

mysql:
image: mysql:8.0
container_name: dungbeetle-test-mysql
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: mydb
MYSQL_USER: user
MYSQL_PASSWORD: userpassword
ports:
- "3306:3306"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "--password=rootpassword"]
interval: 10s
timeout: 5s
retries: 5
networks:
- dungbeetle-test
command: --default-authentication-plugin=mysql_native_password

networks:
dungbeetle-test:
driver: bridge
Loading