|
| 1 | +# Integration tests |
| 2 | + |
| 3 | +Integration tests that exercise the code against a real ClickHouse instance. |
| 4 | + |
| 5 | +This document explains how to run integration tests locally and how to wire them into CI in a safe way. |
| 6 | + |
| 7 | +Prerequisites |
| 8 | + |
| 9 | +- Docker (used for the example below). |
| 10 | +- docker-compose (optional, if you prefer a compose-based setup). |
| 11 | + |
| 12 | +Recommended local setup (Docker Compose) |
| 13 | + |
| 14 | +1. Start ClickHouse with docker-compose (example): |
| 15 | + |
| 16 | +```bash |
| 17 | +# from the repository root, if you have a docker-compose.yml configured |
| 18 | +docker-compose up -d |
| 19 | +``` |
| 20 | + |
| 21 | +2. Wait for the server to be ready: |
| 22 | + |
| 23 | +```bash |
| 24 | +docker-compose ps |
| 25 | +``` |
| 26 | + |
| 27 | +3. Run only the integration tests: |
| 28 | + |
| 29 | +```bash |
| 30 | +# from the repository root |
| 31 | +gleam test test/integration |
| 32 | +``` |
| 33 | + |
| 34 | +4. Tear down the environment when finished: |
| 35 | + |
| 36 | +```bash |
| 37 | +docker-compose down -v |
| 38 | +``` |
| 39 | + |
| 40 | +Quick single-container alternative (no compose) |
| 41 | + |
| 42 | +```bash |
| 43 | +docker run -d --name clickhouse-server -p 8123:8123 -p 9000:9000 clickhouse/clickhouse-server:latest |
| 44 | +# wait for readiness, then run tests |
| 45 | +gleam test test/integration |
| 46 | +docker stop clickhouse-server && docker rm clickhouse-server |
| 47 | +``` |
| 48 | + |
| 49 | +Connection details (local defaults) |
| 50 | + |
| 51 | +- URL: http://localhost:8123 |
| 52 | +- Database: test_db (tests may create/drop their own DBs) |
| 53 | +- User: test_user |
| 54 | +- Password: test_password |
| 55 | + |
| 56 | +If your tests require different credentials or endpoints, set the appropriate environment variables (see the `Environment variables` section below). |
| 57 | + |
| 58 | +Implemented integration tests |
| 59 | + |
| 60 | +- `basic_connectivity_test.gleam` — verifies connection and basic queries |
| 61 | +- `complex_types_roundtrip_test.gleam` — round-trip tests for complex ClickHouse types |
| 62 | +- `format_compatibility_test.gleam` — tests different I/O formats (JSONEachRow, CSV, TabSeparated) |
| 63 | +- `performance_test.gleam` — optional performance/load checks (may be slow) |
| 64 | + |
| 65 | +Environment variables |
| 66 | + |
| 67 | +Use environment variables to configure endpoints and credentials for integration tests. Example: |
| 68 | + |
| 69 | +```bash |
| 70 | +export CLICKHOUSE_URL=http://localhost:8123 |
| 71 | +export CLICKHOUSE_USER=test_user |
| 72 | +export CLICKHOUSE_PASSWORD=test_password |
| 73 | +``` |
| 74 | + |
| 75 | +Document required environment variables and secrets clearly before enabling integration jobs in CI. |
| 76 | + |
| 77 | +CI guidance |
| 78 | + |
| 79 | +- Integration tests should not run by default on every PR. Run them in separate CI jobs, e.g. on manual dispatch, nightly builds, or release tags. |
| 80 | +- Example GitHub Actions job (run in a dedicated workflow or as a separate job): |
| 81 | + |
| 82 | +```yaml |
| 83 | +- name: Integration tests (optional) |
| 84 | + run: | |
| 85 | + docker-compose up -d |
| 86 | + # optionally wait / healthcheck |
| 87 | + sleep 10 |
| 88 | + gleam test test/integration |
| 89 | + docker-compose down -v |
| 90 | + # do not fail the whole pipeline if integration env is missing |
| 91 | + continue-on-error: true |
| 92 | +``` |
| 93 | +
|
| 94 | +Notes and recommendations |
| 95 | +
|
| 96 | +- Keep integration tests isolated and idempotent: tests should create and drop any resources they need. |
| 97 | +- Mark expensive or flaky tests (e.g. `performance_test.gleam`) so CI can skip them unless explicitly requested. |
| 98 | +- Before enabling integration tests in CI, ensure any required secrets or credentials are set in the CI environment. |
0 commit comments