1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-21 13:15:38 +02:00

use actix_rt::test for test setup

This commit is contained in:
Nikolay Kim
2019-11-26 11:25:50 +06:00
parent c1c44a7dd6
commit 4dc31aac93
80 changed files with 6502 additions and 7237 deletions

View File

@@ -105,62 +105,56 @@ mod tests {
use super::*;
use crate::dev::ServiceRequest;
use crate::test::{block_on, call_service, init_service, TestRequest};
use crate::test::{call_service, init_service, TestRequest};
use crate::{web, App, HttpResponse};
#[test]
fn test_wrap() {
block_on(async {
let mut app = init_service(
App::new()
.wrap(NormalizePath::default())
.service(web::resource("/v1/something/").to(|| HttpResponse::Ok())),
)
.await;
#[actix_rt::test]
async fn test_wrap() {
let mut app = init_service(
App::new()
.wrap(NormalizePath::default())
.service(web::resource("/v1/something/").to(|| HttpResponse::Ok())),
)
.await;
let req = TestRequest::with_uri("/v1//something////").to_request();
let res = call_service(&mut app, req).await;
assert!(res.status().is_success());
})
let req = TestRequest::with_uri("/v1//something////").to_request();
let res = call_service(&mut app, req).await;
assert!(res.status().is_success());
}
#[test]
fn test_in_place_normalization() {
block_on(async {
let srv = |req: ServiceRequest| {
assert_eq!("/v1/something/", req.path());
ok(req.into_response(HttpResponse::Ok().finish()))
};
#[actix_rt::test]
async fn test_in_place_normalization() {
let srv = |req: ServiceRequest| {
assert_eq!("/v1/something/", req.path());
ok(req.into_response(HttpResponse::Ok().finish()))
};
let mut normalize = NormalizePath
.new_transform(srv.into_service())
.await
.unwrap();
let mut normalize = NormalizePath
.new_transform(srv.into_service())
.await
.unwrap();
let req = TestRequest::with_uri("/v1//something////").to_srv_request();
let res = normalize.call(req).await.unwrap();
assert!(res.status().is_success());
})
let req = TestRequest::with_uri("/v1//something////").to_srv_request();
let res = normalize.call(req).await.unwrap();
assert!(res.status().is_success());
}
#[test]
fn should_normalize_nothing() {
block_on(async {
const URI: &str = "/v1/something/";
#[actix_rt::test]
async fn should_normalize_nothing() {
const URI: &str = "/v1/something/";
let srv = |req: ServiceRequest| {
assert_eq!(URI, req.path());
ok(req.into_response(HttpResponse::Ok().finish()))
};
let srv = |req: ServiceRequest| {
assert_eq!(URI, req.path());
ok(req.into_response(HttpResponse::Ok().finish()))
};
let mut normalize = NormalizePath
.new_transform(srv.into_service())
.await
.unwrap();
let mut normalize = NormalizePath
.new_transform(srv.into_service())
.await
.unwrap();
let req = TestRequest::with_uri(URI).to_srv_request();
let res = normalize.call(req).await.unwrap();
assert!(res.status().is_success());
})
let req = TestRequest::with_uri(URI).to_srv_request();
let res = normalize.call(req).await.unwrap();
assert!(res.status().is_success());
}
}