From 6ca1c896100ca906f650e87812662a5937520b26 Mon Sep 17 00:00:00 2001 From: xphoniex Date: Fri, 17 Feb 2023 14:29:48 +0000 Subject: [PATCH] httpd: Update `/git` test to use `test` helper fns Update `axum` to 0.6.7 to be able to use fix in: https://github.com/tokio-rs/axum/pull/1767 Signed-off-by: xphoniex --- Cargo.lock | 4 ++-- radicle-httpd/Cargo.toml | 2 +- radicle-httpd/src/git.rs | 22 ++++++---------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f52e4133..5ac93c67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,9 +121,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.4" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5694b64066a2459918d8074c2ce0d5a88f409431994c2356617c8ae0c4721fc" +checksum = "2fb79c228270dcf2426e74864cabc94babb5dbab01a4314e702d2f16540e1591" dependencies = [ "async-trait", "axum-core", diff --git a/radicle-httpd/Cargo.toml b/radicle-httpd/Cargo.toml index fff78581..fa7b5c2a 100644 --- a/radicle-httpd/Cargo.toml +++ b/radicle-httpd/Cargo.toml @@ -16,7 +16,7 @@ logfmt = [ [dependencies] anyhow = { version = "1" } -axum = { version = "0.6.2", default-features = false, features = ["headers", "json", "query", "tokio"] } +axum = { version = "0.6.7", default-features = false, features = ["headers", "json", "query", "tokio"] } axum-auth = { version= "0.4.0", default-features = false, features = ["auth-bearer"] } axum-server = { version = "0.4.4", default-features = false } chrono = { version = "0.4.22" } diff --git a/radicle-httpd/src/git.rs b/radicle-httpd/src/git.rs index e7aab600..0785f096 100644 --- a/radicle-httpd/src/git.rs +++ b/radicle-httpd/src/git.rs @@ -197,29 +197,19 @@ async fn git_http_backend( mod routes { use std::net::SocketAddr; - use axum::body::Body; - use axum::extract::ConnectInfo; - use axum::http::Request; - use axum::http::{Method, StatusCode}; - use tower::ServiceExt; + use axum::extract::connect_info::MockConnectInfo; + use axum::http::StatusCode; - use crate::test; + use crate::test::{self, get}; #[tokio::test] async fn test_invalid_route_returns_404() { let tmp = tempfile::tempdir().unwrap(); let ctx = test::seed(tmp.path()); - let app = super::router(ctx.profile().to_owned()); + let app = super::router(ctx.profile().to_owned()) + .layer(MockConnectInfo(SocketAddr::from(([0, 0, 0, 0], 8080)))); - let request = Request::builder() - .method(Method::GET) - .uri("/aa/a".to_string()); - - let mut request = request.body(Body::empty()).unwrap(); - let socket_addr: SocketAddr = "127.0.0.1:8080".parse().unwrap(); - request.extensions_mut().insert(ConnectInfo(socket_addr)); - - let response = app.oneshot(request).await.unwrap(); + let response = get(&app, "/aa/a").await; assert_eq!(response.status(), StatusCode::NOT_FOUND); }