Cleanup files when testing sqlite storage

This commit is contained in:
Maybe Waffle 2022-03-14 22:05:15 +04:00
parent 8ae3222409
commit 3c97ed83f4

View file

@ -1,36 +1,47 @@
use std::{ use std::{
fmt::{Debug, Display}, fmt::{Debug, Display},
fs,
sync::Arc, sync::Arc,
}; };
use teloxide::dispatching::dialogue::{Serializer, SqliteStorage, SqliteStorageError, Storage}; use teloxide::dispatching::dialogue::{Serializer, SqliteStorage, SqliteStorageError, Storage};
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_sqlite_json() { async fn test_sqlite_json() {
let storage = fs::create_dir("./test_db1").unwrap();
SqliteStorage::open("./test_db1.sqlite", teloxide::dispatching::dialogue::serializer::Json) let storage = SqliteStorage::open(
.await "./test_db1/test_db1.sqlite",
.unwrap(); teloxide::dispatching::dialogue::serializer::Json,
)
.await
.unwrap();
test_sqlite(storage).await; test_sqlite(storage).await;
fs::remove_dir_all("./test_db1").unwrap();
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_sqlite_bincode() { async fn test_sqlite_bincode() {
fs::create_dir("./test_db2").unwrap();
let storage = SqliteStorage::open( let storage = SqliteStorage::open(
"./test_db2.sqlite", "./test_db2/test_db2.sqlite",
teloxide::dispatching::dialogue::serializer::Bincode, teloxide::dispatching::dialogue::serializer::Bincode,
) )
.await .await
.unwrap(); .unwrap();
test_sqlite(storage).await; test_sqlite(storage).await;
fs::remove_dir_all("./test_db2").unwrap();
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_sqlite_cbor() { async fn test_sqlite_cbor() {
let storage = fs::create_dir("./test_db3").unwrap();
SqliteStorage::open("./test_db3.sqlite", teloxide::dispatching::dialogue::serializer::Cbor) let storage = SqliteStorage::open(
.await "./test_db3/test_db3.sqlite",
.unwrap(); teloxide::dispatching::dialogue::serializer::Cbor,
)
.await
.unwrap();
test_sqlite(storage).await; test_sqlite(storage).await;
fs::remove_dir_all("./test_db3").unwrap();
} }
type Dialogue = String; type Dialogue = String;