Skip to content

Commit

Permalink
Verify existence of file
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallku committed Sep 3, 2024
1 parent 3c01f35 commit 83eddbb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/controllers/__tests__/images.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(test)]
mod tests {

use std::path::PathBuf;

use axum::{
body::Body,
http::{Request, StatusCode},
Expand All @@ -9,7 +11,7 @@ mod tests {
};
use tower::ServiceExt;

use crate::{controllers::images, env::state::AppState};
use crate::{constants::CDN_ROOT, controllers::images, env::state::AppState};

const URI: &str = "/images";

Expand All @@ -18,20 +20,20 @@ mod tests {
let app: Router<AppState> =
Router::new().route(&format!("{}/*path", URI), get(images::get));
let state = AppState::from_env();
let file_path = "/images/hpp/ic_wahlberg_product_core_48.png8.png";
let response = app
.with_state(state)
.oneshot(
Request::builder()
.uri(format!(
"{}/images/hpp/ic_wahlberg_product_core_48.png8.png",
URI
))
.uri(format!("{}{}", URI, file_path))
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
let local_file_path = PathBuf::from(format!("{}{}{}", CDN_ROOT, URI, file_path));

assert_eq!(response.status(), StatusCode::OK);
assert!(local_file_path.exists());
}
}

0 comments on commit 83eddbb

Please sign in to comment.