+
+#[cfg(test)]
+mod tests {
+ use axum::{
+ http::{Request, StatusCode},
+ response::Response,
+ body::Body
+ };
+ use tower::ServiceExt; // for `oneshot`
+
+ async fn assert_res_ok_body(res: Response, expected_body: &[u8]) {
+ assert_eq!(res.status(), StatusCode::OK);
+ assert_eq!(hyper::body::to_bytes(res.into_body()).await.unwrap(), expected_body);
+ }
+
+ #[tokio::test]
+ async fn test_hello() {
+ // no user-agent
+ let res = super::app()
+ .oneshot(Request::builder().uri("/hello/rust").body(Body::empty()).unwrap())
+ .await
+ .unwrap();
+ assert_res_ok_body(res, b"Hello rust").await;
+
+ // with user-agent
+ let res = super::app()
+ .oneshot(Request::builder()
+ .uri("/hello/rust")
+ .header("user-agent", "TestBrowser 0.1")
+ .body(Body::empty()).unwrap())
+ .await
+ .unwrap();
+ assert_res_ok_body(res, b"Hello rust from TestBrowser 0.1").await;
+ }
+}