sqlness
SQL integration test harNESS
An ergonomic, opinionated framework for SQL integration test.
Usage
SQLNESS can be used as library or as command lines tool directly, it support MySQL/PostgreSQL wire protocol.
Use as library
First add sqlness to your project:
Then implement Database
and EnvController
trait to setup your tests. Refer basic.rs for a complete example.
Use as CLI
One example used in our CI is
It will test against a MySQL server listening on 127.0.0.1:3306
Testcase structures
This is the directory structure of testcase for basic-example:
$ tree examples/
examples/
├── basic-case # Testcase root directory
│ └── simple # One environment
│ ├── config.toml # Config file for current environment, optional
│ ├── select.result # Output result file
│ └── select.sql # Input SQL testcase
├── basic.rs # Entrypoint of this example
When run it via
It will do following things:
- Collect all environments(first-level directory) under
basic-case
. - Run tests(
.sql
files) under environment one after one.- Before execution it will read
{testcase}.result
(create one if not exists) to memory for compare. - During execution it will collect query response and write to
{testcase}.result
- After execution it will compare the generated
{testcase}.result
with previous one, PASS when they are the same, and FAIL otherwise.
- Before execution it will read
- Report result.
Usually result
files should be tracked in git, whenever there are failed tests, users should
- Update
result
to latest version(e.g.git add
) if the newer result is right, or - Restore
result
back to original version (e.g.git checkout
), troubleshoot bugs in database implementation, and run tests again
Flowchart below illustrates the typical steps when write a test.
Below is the output of this example:
)
Who is using
- CeresDB, a high-performance, distributed, cloud native time-series database that can handle both time-series and analytics workloads.
- GreptimeDB, an open-source, cloud-native, distributed time-series database.
If you’re using sqlness and like to be added to this list, welcome to open a PR.
License
This project is under Apache License 2.0.