1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

test(files): Fix test and remove outdated case (#2037)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Florian Dreschner 2021-03-01 00:01:59 +01:00 committed by GitHub
parent abc7fd374b
commit fb019f15b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -662,8 +662,12 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_static_files_bad_directory() { async fn test_static_files_bad_directory() {
let _st: Files = Files::new("/", "missing"); let service = Files::new("/", "./missing").new_service(()).await.unwrap();
let _st: Files = Files::new("/", "Cargo.toml");
let req = TestRequest::with_uri("/").to_srv_request();
let resp = test::call_service(&service, req).await;
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
} }
#[actix_rt::test] #[actix_rt::test]
@ -676,75 +680,34 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let req = TestRequest::with_uri("/missing").to_srv_request(); let req = TestRequest::with_uri("/missing").to_srv_request();
let resp = test::call_service(&st, req).await; let resp = test::call_service(&st, req).await;
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
let bytes = test::read_body(resp).await; let bytes = test::read_body(resp).await;
assert_eq!(bytes, web::Bytes::from_static(b"default content")); assert_eq!(bytes, web::Bytes::from_static(b"default content"));
} }
// #[actix_rt::test] #[actix_rt::test]
// async fn test_serve_index() { async fn test_serve_index_nested() {
// let st = Files::new(".").index_file("test.binary"); let service = Files::new(".", ".")
// let req = TestRequest::default().uri("/tests").finish(); .index_file("lib.rs")
.new_service(())
.await
.unwrap();
// let resp = st.handle(&req).respond_to(&req).unwrap(); let req = TestRequest::default().uri("/src").to_srv_request();
// let resp = resp.as_msg(); let resp = test::call_service(&service, req).await;
// assert_eq!(resp.status(), StatusCode::OK);
// assert_eq!(
// resp.headers()
// .get(header::CONTENT_TYPE)
// .expect("content type"),
// "application/octet-stream"
// );
// assert_eq!(
// resp.headers()
// .get(header::CONTENT_DISPOSITION)
// .expect("content disposition"),
// "attachment; filename=\"test.binary\""
// );
// let req = TestRequest::default().uri("/tests/").finish(); assert_eq!(resp.status(), StatusCode::OK);
// let resp = st.handle(&req).respond_to(&req).unwrap(); assert_eq!(
// let resp = resp.as_msg(); resp.headers().get(header::CONTENT_TYPE).unwrap(),
// assert_eq!(resp.status(), StatusCode::OK); "text/x-rust"
// assert_eq!( );
// resp.headers().get(header::CONTENT_TYPE).unwrap(), assert_eq!(
// "application/octet-stream" resp.headers().get(header::CONTENT_DISPOSITION).unwrap(),
// ); "inline; filename=\"lib.rs\""
// assert_eq!( );
// resp.headers().get(header::CONTENT_DISPOSITION).unwrap(), }
// "attachment; filename=\"test.binary\""
// );
// // nonexistent index file
// let req = TestRequest::default().uri("/tests/unknown").finish();
// let resp = st.handle(&req).respond_to(&req).unwrap();
// let resp = resp.as_msg();
// assert_eq!(resp.status(), StatusCode::NOT_FOUND);
// let req = TestRequest::default().uri("/tests/unknown/").finish();
// let resp = st.handle(&req).respond_to(&req).unwrap();
// let resp = resp.as_msg();
// assert_eq!(resp.status(), StatusCode::NOT_FOUND);
// }
// #[actix_rt::test]
// async fn test_serve_index_nested() {
// let st = Files::new(".").index_file("mod.rs");
// let req = TestRequest::default().uri("/src/client").finish();
// let resp = st.handle(&req).respond_to(&req).unwrap();
// let resp = resp.as_msg();
// assert_eq!(resp.status(), StatusCode::OK);
// assert_eq!(
// resp.headers().get(header::CONTENT_TYPE).unwrap(),
// "text/x-rust"
// );
// assert_eq!(
// resp.headers().get(header::CONTENT_DISPOSITION).unwrap(),
// "inline; filename=\"mod.rs\""
// );
// }
#[actix_rt::test] #[actix_rt::test]
async fn integration_serve_index() { async fn integration_serve_index() {