1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-21 23:00:50 +03:00

Add test helpers for handlers and use them

Also expands the test coverage of the revoke handler.
This commit is contained in:
Quentin Gliech
2023-02-21 11:44:52 +01:00
parent a6cd4412c1
commit 64ce271d08
5 changed files with 561 additions and 162 deletions

View File

@@ -31,24 +31,18 @@ pub async fn get(State(pool): State<PgPool>) -> Result<impl IntoResponse, FancyE
#[cfg(test)]
mod tests {
use hyper::{Body, Request, StatusCode};
use tower::ServiceExt;
use hyper::{Request, StatusCode};
use super::*;
use crate::test_utils::{RequestBuilderExt, ResponseExt, TestState};
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
async fn test_get_health(pool: PgPool) -> Result<(), anyhow::Error> {
let state = crate::test_state(pool).await?;
let app = crate::healthcheck_router().with_state(state);
async fn test_get_health(pool: PgPool) {
let state = TestState::from_pool(pool).await.unwrap();
let request = Request::get("/health").empty();
let request = Request::builder().uri("/health").body(Body::empty())?;
let response = app.oneshot(request).await?;
assert_eq!(response.status(), StatusCode::OK);
let body = hyper::body::to_bytes(response.into_body()).await?;
assert_eq!(body, "ok");
Ok(())
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
assert_eq!(response.body(), "ok");
}
}