2 releases
0.2.1 | Jan 15, 2023 |
---|---|
0.2.0 | Dec 27, 2022 |
#2097 in Database interfaces
11KB
114 lines
couch_rs_test
Tools for testing a CouchDB repository implemented in Rust with couch_rs
lib.rs
:
A set of helper functions for executing tests with couch_rs library
Allows easy execution of tests by providing automated creation and destruction of test databases in a CouchDB instance. For a given database name, the created databases append a random string to guarantee uniqueness of multiple tests in parallel in the same CouchDB instance.
use serde_json::json;
use couch_rs_test::{TestRepo, TestRepoConfig};
async fn new_database(
config_uri: &str,
config_username: &str,
config_password: &str,
config_dbname: &str,
) -> TestRepo {
let repo: TestRepo = match TestRepo::new(
TestRepoConfig::new(
config_uri,
config_username,
config_password,
config_dbname,
)
).await {
Ok(r) => r,
// if db creation fails, test will fail, so just panic
Err(e) => panic!("Failed to create test database: {}", e),
};
// write test data into the newly created database
let data = &mut vec!{
json!{{"some": "data"}},
json!{{"some": "other-data"}}
};
match repo.with_data(data).await {
Ok(cnt) => log::info!("Added {} entries to test database {}", cnt, repo.db.name()),
Err(e) => panic!("Failed to set up database: {}", e),
};
repo
}
Dependencies
~7–20MB
~273K SLoC