Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support axum 0.8.0 #31

Open
sondrelg opened this issue Jan 7, 2025 · 1 comment
Open

Support axum 0.8.0 #31

sondrelg opened this issue Jan 7, 2025 · 1 comment

Comments

@sondrelg
Copy link

sondrelg commented Jan 7, 2025

Hi @renancloudwalk. Thanks for creating this, it's been really nice to use 👌

Just wanted to let you know, the axum 0.8.0 release seems to require an update:

error[E0308]: mismatched types
   --> src/foo.rs:180:38
    |
180 |         let client = TestClient::new(app).await;
    |                      --------------- ^^^ expected `axum::routing::Router`, found `Router`
    |                      |
    |                      arguments to this function are incorrect

Do you think you'll have time to publish a compatibility fix?

@sawmurai
Copy link

In case anyone is interested in how a migration away from TestClient looks like:

get_app().await returns a Router (it also has state that is created async, hence the .await)

Works with axum 0.8.1.

     #[tokio::test]
     async fn returns_list_of_exercises() {
-        let client = TestClient::new(get_app().await).await;
+        let mut app = get_app().await;
+        let cookie = login_coach(&mut app).await;
 
-        let cookie = login_coach(&client).await;
-        let res = client
-            .get("/exercise")
+        let req = Request::builder()
+            .method("GET")
+            .uri("/exercise")
             .header("cookie", &cookie)
-            .send()
-            .await;
+            .body(Body::empty())
+            .unwrap();
+
+        let res = app.oneshot(req).await.unwrap();
         assert_eq!(res.status(), StatusCode::OK);
 
         let expected = r#"[{"id":"88dc900e-82c1-11ed-93b1-cfc2854f95b8","name":"Deadlift","groupId":null,"active":true,"userId":"d9ae8e47-112f-4d37-ba20-0cb1dbc776b6","metricType":"weight","usedCount":0,"offset":0}]"#;
-        assert_eq!(res.text().await, expected);
+        let body = axum::body::to_bytes(res.into_body(), 1000000)
+            .await
+            .unwrap();
+        assert_eq!(std::str::from_utf8(&body).unwrap(), expected);
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants