use a fresh db for each test
This commit is contained in:
parent
741268ef1e
commit
458207cea3
2 changed files with 8 additions and 20 deletions
|
@ -13,7 +13,7 @@ async fn login_succeeds_with_valid_credentials() -> Result<()> {
|
||||||
let resp = client
|
let resp = client
|
||||||
.post(server.url("/auth/signup"))
|
.post(server.url("/auth/signup"))
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.body("email=admin1&password=hunter2")
|
.body("email=admin&password=hunter2")
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ async fn login_succeeds_with_valid_credentials() -> Result<()> {
|
||||||
let resp = client
|
let resp = client
|
||||||
.post(server.url("/auth/login"))
|
.post(server.url("/auth/login"))
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.body("email=admin1&password=hunter2")
|
.body("email=admin&password=hunter2")
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ async fn login_fails_with_invalid_credentials() -> Result<()> {
|
||||||
let resp = client
|
let resp = client
|
||||||
.post(server.url("/auth/signup"))
|
.post(server.url("/auth/signup"))
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.body("email=admin2&password=hunter2")
|
.body("email=admin&password=hunter2")
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ async fn login_fails_with_invalid_credentials() -> Result<()> {
|
||||||
let resp = client
|
let resp = client
|
||||||
.post(server.url("/auth/login"))
|
.post(server.url("/auth/login"))
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.body("email=admin2&password=hunter3")
|
.body("email=admin&password=hunter3")
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::{bail, Result};
|
use anyhow::Result;
|
||||||
use bollard::query_parameters::{CreateImageOptionsBuilder, ListContainersOptionsBuilder};
|
use bollard::query_parameters::{CreateImageOptionsBuilder, ListContainersOptionsBuilder};
|
||||||
use bollard::secret::{
|
use bollard::secret::{
|
||||||
ContainerCreateBody, ContainerInspectResponse, ContainerState, CreateImageInfo, Health,
|
ContainerCreateBody, ContainerInspectResponse, ContainerState, CreateImageInfo, Health,
|
||||||
|
@ -12,26 +12,16 @@ use sqlx::migrate::MigrateDatabase;
|
||||||
use sqlx::{Connection, PgConnection};
|
use sqlx::{Connection, PgConnection};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::sync::OnceCell;
|
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, trace};
|
||||||
use zero_to_axum::{conf, Conf, ZeroToAxum};
|
use zero_to_axum::{conf, Conf, ZeroToAxum};
|
||||||
|
|
||||||
static SHARED_DB: OnceCell<Arc<TestDb>> = OnceCell::const_new();
|
|
||||||
async fn get_shared_db() -> Arc<TestDb> {
|
|
||||||
SHARED_DB
|
|
||||||
.get_or_init(|| async { Arc::new(TestDb::spawn().await) })
|
|
||||||
.await
|
|
||||||
.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TestServer {
|
pub struct TestServer {
|
||||||
server_task_handle: JoinHandle<()>,
|
server_task_handle: JoinHandle<()>,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
db: Arc<TestDb>,
|
_db: TestDb,
|
||||||
pub mock_smtp_server: maik::MockServer,
|
pub mock_smtp_server: maik::MockServer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +29,7 @@ impl TestServer {
|
||||||
pub async fn spawn() -> TestServer {
|
pub async fn spawn() -> TestServer {
|
||||||
debug!("start test server");
|
debug!("start test server");
|
||||||
|
|
||||||
// TODO: allow per-test DBs in some cases
|
let db = TestDb::spawn().await;
|
||||||
// let db = TestDb::spawn().await;
|
|
||||||
let db = get_shared_db().await;
|
|
||||||
let url = dbg!(db.get_url());
|
let url = dbg!(db.get_url());
|
||||||
|
|
||||||
let mock_smtp_server = maik::MockServer::builder()
|
let mock_smtp_server = maik::MockServer::builder()
|
||||||
|
@ -76,7 +64,7 @@ impl TestServer {
|
||||||
TestServer {
|
TestServer {
|
||||||
server_task_handle,
|
server_task_handle,
|
||||||
addr,
|
addr,
|
||||||
db,
|
_db: db,
|
||||||
mock_smtp_server,
|
mock_smtp_server,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue