httpd: Change `500` into `404` when project doesn't exist
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
parent
be5afcc600
commit
c1b6ceb141
|
|
@ -1,3 +1,6 @@
|
|||
#[cfg(test)]
|
||||
pub mod test;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
|
@ -22,8 +25,6 @@ mod auth;
|
|||
mod axum_extra;
|
||||
mod error;
|
||||
mod json;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
mod v1;
|
||||
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
|
@ -64,6 +65,11 @@ impl Context {
|
|||
id,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn profile(&self) -> &Arc<Profile> {
|
||||
&self.profile
|
||||
}
|
||||
}
|
||||
|
||||
pub fn router(ctx: Context) -> Router {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ impl Error {
|
|||
match self {
|
||||
Error::ServiceUnavailable(_) => http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
Error::InvalidId => http::StatusCode::NOT_FOUND,
|
||||
Error::Id(_) => http::StatusCode::NOT_FOUND,
|
||||
_ => http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,3 +192,35 @@ async fn git_http_backend(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
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 crate::api::test;
|
||||
|
||||
#[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 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();
|
||||
|
||||
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue