testfixtures
testfixtures is a Rust library for preparing test data from yaml files.
Install
This crate is compatible with the async-std and tokio runtimes.
async-std
[]
= "0.1"
= "0.3"
= "0.4.11"
tokio
[]
= { = "0.1", = false, = [ "runtime-tokio" ] }
= { = "0.3", = false, = [ "runtime-tokio", "macros" ] }
= "0.4.11"
Usage
Create fixture files like the following.
todos.yml
- id: 1
description: buy a new camera
done: true
progress: 10.5
created_at: 2020/01/01 01:01:01
- id: 2
description: meeting
done: false
progress: 30.0
created_at: 2020/01/01 02:02:02
2020-01-01 01:01
2020-01-01 01:01:01
20200101 01:01
20200101 01:01:01
01012020 01:01
01012020 01:01:01
2020/01/01 01:01
2020/01/01 01:01:01
If you need to write raw SQL, probably to call a function, prefix the value of the column with RAW=.
- id: 1
description: fizz
done: true
progress: 10.5
created_at: RAW=NOW()
Your tests would look like this.
PgLoader and SqliteLoader are under development.
Options
database(required)
database is a option for passing db connection pool to a Loader.
let pool = new.await?;
let loader = new
.await?;
location(required)
location is a option for setting timezone.
use Utc;
let loader = new
.await?;
skip_test_database_check(optional)
skip_test_database_check is a option for setting a flag for checking if database name ends with "test".
let loader = new
.await?;
files(optional)
files is a option for reading your fixture files.
let loader = new
.await?;
directory(optional)
files is a option for reading your fixture files in a directory.
let loader = new
.await?;
paths(optional)
paths is a option that is a combination of files option and directory option.
let loader = new
.await?;
Implemation status
Database
- MySQL and MariaDB
- Postgres
- SQLite
Options
- database
- load files
- skip_test_database_check
- location
- directory
- paths
- template
Contribution
# setup test db
# load environment variables
# run unit tests