test: Add tests for xml and toml

This commit is contained in:
gengteng
2023-12-04 11:56:59 +08:00
parent 8acf2c2ff6
commit 6e0b45b05f
3 changed files with 295 additions and 0 deletions

View File

@@ -140,6 +140,12 @@ async fn test_main() -> anyhow::Result<()> {
post(msgpack::extract_msgpack_raw),
);
#[cfg(feature = "xml")]
let router = router.route(xml::route::XML, post(xml::extract_xml));
#[cfg(feature = "toml")]
let router = router.route(toml::route::TOML, post(toml::extract_toml));
let router = router.with_state(MyState::default());
let listener = TcpListener::bind(&SocketAddr::from(([0u8, 0, 0, 0], 0u16))).await?;
@@ -388,6 +394,22 @@ async fn test_main() -> anyhow::Result<()> {
.await?;
}
#[cfg(feature = "xml")]
{
use axum_serde::Xml;
test_executor
.execute::<Xml<ParametersGarde>>(Method::POST, xml::route::XML)
.await?;
}
#[cfg(feature = "toml")]
{
use axum_serde::Toml;
test_executor
.execute::<Toml<ParametersGarde>>(Method::POST, toml::route::TOML)
.await?;
}
Ok(())
}
@@ -887,3 +909,35 @@ mod msgpack {
validate_again(parameters, ())
}
}
#[cfg(feature = "xml")]
mod xml {
use super::{validate_again, ParametersGarde};
use crate::Garde;
use axum::http::StatusCode;
use axum_serde::Xml;
pub mod route {
pub const XML: &str = "/xml";
}
pub async fn extract_xml(Garde(Xml(parameters)): Garde<Xml<ParametersGarde>>) -> StatusCode {
validate_again(parameters, ())
}
}
#[cfg(feature = "toml")]
mod toml {
use super::{validate_again, ParametersGarde};
use crate::Garde;
use axum::http::StatusCode;
use axum_serde::Toml;
pub mod route {
pub const TOML: &str = "/toml";
}
pub async fn extract_toml(Garde(Toml(parameters)): Garde<Toml<ParametersGarde>>) -> StatusCode {
validate_again(parameters, ())
}
}