Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ tests/emulator/emulator.exe
SECURITY_AUDIT_REPORT.md

*.exe

docs/
5 changes: 3 additions & 2 deletions tests/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ EVENTS_QUEUE_ENDPOINT=http://localhost:8000/v1/events
EVENTS_QUEUE_USER_API_KEY=system-user-api-key
EVENTS_QUEUE_USER_ID=system-user-id
FCM_ENDPOINT=http://wiremock:8080
DATABASE_URL=postgresql://dbusername:dbpassword@postgres:5432/httpsms
DATABASE_URL_DEDICATED=postgresql://dbusername:dbpassword@postgres:5432/httpsms
DATABASE_URL=postgresql://root@cockroachdb:26257/httpsms?sslmode=disable
DATABASE_URL_DEDICATED=postgresql://root@cockroachdb:26257/httpsms?sslmode=disable
DATABASE_MIGRATION_CONSTRAINT_FIX=1
REDIS_URL=redis://@redis:6379
APP_PORT=8000
APP_NAME=httpSMS
Expand Down
26 changes: 13 additions & 13 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ End-to-end integration tests for the httpSMS API. These tests validate the compl
└──────────────┘
┌──────┴───────┐
PostgreSQL │ │ Redis │
│ Port 5435 │ │ Port 6379 │
CockroachDB │ │ Redis │
│ Port 26257 │ │ Port 6379 │
└──────────────┘ └─────────────┘
```

### Components

| Component | Description |
| --------------- | ------------------------------------------------------- |
| **API** | The httpSMS Go API server running in Docker |
| **Emulator** | A Fiber v3 Go service that simulates an Android phone |
| **PostgreSQL** | Database for the API |
| **Redis** | Cache and queue backend |
| **Seed** | One-shot container that seeds test data into PostgreSQL |
| **Test Runner** | Go test binary that runs on the host machine |
| Component | Description |
| --------------- | -------------------------------------------------------- |
| **API** | The httpSMS Go API server running in Docker |
| **Emulator** | A Fiber v3 Go service that simulates an Android phone |
| **CockroachDB** | Database for the API (single-node, insecure mode) |
| **Redis** | Cache and queue backend |
| **Seed** | One-shot container that seeds test data into CockroachDB |
| **Test Runner** | Go test binary that runs on the host machine |

### How It Works

Expand Down Expand Up @@ -86,7 +86,7 @@ export FIREBASE_CREDENTIALS=$(jq -c . firebase-credentials.json)
docker compose up -d --build --wait
```

This starts PostgreSQL, Redis, the API, and the emulator. The `--wait` flag blocks until all health checks pass.
This starts CockroachDB, Redis, the API, and the emulator. The `--wait` flag blocks until all health checks pass.

### 4. Wait for Seeding

Expand All @@ -95,7 +95,7 @@ docker compose wait seed
sleep 2
```

The seed container inserts test users, phones, and API keys into PostgreSQL after the API has run its GORM migrations.
The seed container inserts test users, phones, and API keys into CockroachDB after the API has run its GORM migrations.

### 5. Run Tests

Expand Down Expand Up @@ -181,7 +181,7 @@ docker compose logs api
Common issues:

- `FIREBASE_CREDENTIALS` env var not set or malformed
- PostgreSQL not ready (increase `start_period` in healthcheck)
- CockroachDB not ready (increase `start_period` in healthcheck)

### Tests timeout waiting for `delivered` status

Expand Down
62 changes: 39 additions & 23 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
services:
postgres:
image: postgres:alpine
environment:
POSTGRES_DB: httpsms
POSTGRES_PASSWORD: dbpassword
POSTGRES_USER: dbusername
cockroachdb:
image: cockroachdb/cockroach:latest
command: start-single-node --insecure --store=type=mem,size=640MiB
ports:
- "5435:5432"
- "26257:26257"
- "8081:8080"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U dbusername -d httpsms"]
test:
[
Comment thread
AchoArnold marked this conversation as resolved.
"CMD",
"cockroach",
"sql",
"--insecure",
"--host=localhost",
"--execute=SELECT 1;",
]
interval: 5s
timeout: 5s
retries: 10
start_period: 5s
start_period: 10s

cockroachdb-init:
image: cockroachdb/cockroach:latest
depends_on:
cockroachdb:
condition: service_healthy
entrypoint:
[
"cockroach",
"sql",
"--insecure",
"--host=cockroachdb",
"--execute=CREATE DATABASE IF NOT EXISTS httpsms;",
]
restart: "no"

redis:
image: redis:latest
Expand Down Expand Up @@ -61,8 +82,8 @@ services:
ports:
- "8000:8000"
depends_on:
postgres:
condition: service_healthy
cockroachdb-init:
condition: service_completed_successfully
redis:
condition: service_healthy
wiremock:
Expand All @@ -81,24 +102,19 @@ services:
start_period: 30s

seed:
image: postgres:alpine
image: cockroachdb/cockroach:latest
depends_on:
api:
condition: service_healthy
environment:
PGPASSWORD: dbpassword
volumes:
- ./seed.sql:/seed.sql:ro
entrypoint:
[
"psql",
"-h",
"postgres",
"-U",
"dbusername",
"-d",
"httpsms",
"-f",
"/seed.sql",
"cockroach",
"sql",
"--insecure",
"--host=cockroachdb",
"--database=httpsms",
"--file=/seed.sql",
]
restart: "no"
Loading