feat(gpodder_sqlite): switch to on-disk sqlite for tests and benches
This commit is contained in:
parent
d329a0e61c
commit
5f57d85584
5 changed files with 51 additions and 12 deletions
|
|
@ -1,8 +1,17 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use gpodder::{AuthStore, User};
|
||||
use gpodder_sqlite::SqliteRepository;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
|
||||
pub fn setup() -> (SqliteRepository, Vec<User>) {
|
||||
let store = SqliteRepository::in_memory().unwrap();
|
||||
pub fn setup() -> (PathBuf, SqliteRepository, Vec<User>) {
|
||||
let fname: String = rand::thread_rng()
|
||||
.sample_iter(Alphanumeric)
|
||||
.take(10)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
let path = std::env::temp_dir().join(fname);
|
||||
let store = SqliteRepository::from_path(&path).unwrap();
|
||||
let mut users = Vec::new();
|
||||
|
||||
for i in 0..1000 {
|
||||
|
|
@ -12,5 +21,9 @@ pub fn setup() -> (SqliteRepository, Vec<User>) {
|
|||
users.push(store.insert_user(&username, &password_hash).unwrap());
|
||||
}
|
||||
|
||||
(store, users)
|
||||
(path, store, users)
|
||||
}
|
||||
|
||||
pub fn teardown(path: PathBuf) {
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue