# dbtest: container test databases Podman (preferred) or Docker. One tool for postgres, mssql, mysql. ## Commands | Command | Action | |---|---| | `./tests/dbtest/dbtest.sh up ` | Start, wait for ready, run init | | `down ` | Stop and remove | | `restart ` | Fresh container | | `status ` | State and connection string | | `env ` | Print `export` line for the test env var | | `test [pkgs]` | up, `go test`, down | | `shell ` | Interactive client | | `exec ` | Run SQL file | | `logs ` | Container logs | ## Databases | db | Port | Env var | Init | Default test pkgs | |---|---|---|---|---| | postgres | 5439 | `RELSPEC_TEST_PG_CONN` | `tests/postgres/init.sql` | readers/pgsql, writers/pgsql, writers/sqlexec | | mssql | 1439 | `RELSPEC_TEST_MSSQL_CONN` | `test_data/mssql/test_schema.sql` (creates `RelSpecTest`) | readers/mssql, writers/mssql | | mysql | 3309 | `RELSPEC_TEST_MYSQL_CONN` | `tests/dbtest/init/mysql.sql` | none (no Go driver/reader yet) | ## Env | Var | Effect | |---|---| | `DBTEST_RUNTIME` | Force `podman` or `docker` | | `DBTEST_TIMEOUT` | Ready wait, seconds (default 120) | | `DBTEST_KEEP=1` | Keep container after `test` | | `DBTEST_GOFLAGS` | Extra `go test` flags | ## Add a database 1. Add `dbs/.sh` defining: `DB_NAME DB_IMAGE DB_CONTAINER DB_PORT DB_INTERNAL_PORT DB_ENV DB_INIT_MOUNT DB_CONN_VAR DB_CONN DB_DEFAULT_PKGS` and functions `db_ready db_post_init db_shell db_exec_file`. 2. Add the name to `ALL_DBS` in `dbtest.sh`. ## Notes - Containers are named `relspec-test-`; existing `tests/postgres/*.sh` and `make docker-*` use the same postgres name/port 5439 and remain independent. - mssql needs ~2GB RAM and takes longer to become ready. - Tests skip when the env var is unset.