-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
999eef6
commit 8300b82
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
|
||
use std::path::PathBuf; | ||
|
||
use axum::{ | ||
body::Body, | ||
http::{Request, StatusCode}, | ||
}; | ||
use tower::ServiceExt; | ||
|
||
use crate::{constants::CDN_ROOT, controllers::app::app, env::state::AppState}; | ||
|
||
const URI: &str = "/files"; | ||
|
||
#[tokio::test] | ||
async fn test_response_file() { | ||
let app = app(); | ||
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!("{}{}", 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()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_response_error() { | ||
let app = app(); | ||
let state = AppState::from_env(); | ||
let file_path = "/images/you-must-not-exist.png"; | ||
let response = app | ||
.with_state(state) | ||
.oneshot( | ||
Request::builder() | ||
.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::NOT_FOUND); | ||
assert!(!local_file_path.exists()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod files; | ||
mod images; |