mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
Rename test::call_success to test::call_service
This commit is contained in:
parent
09cdf1e302
commit
7a28b32f6d
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
* Rename `RouterConfig` to `ServiceConfig`
|
* Rename `RouterConfig` to `ServiceConfig`
|
||||||
|
|
||||||
|
* Rename `test::call_success` to `test::call_service`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
* Fixed `TestRequest::app_data()`
|
* Fixed `TestRequest::app_data()`
|
||||||
|
10
src/app.rs
10
src/app.rs
@ -436,7 +436,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::http::{header, HeaderValue, Method, StatusCode};
|
use crate::http::{header, HeaderValue, Method, StatusCode};
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
use crate::test::{block_on, call_success, init_service, TestRequest};
|
use crate::test::{block_on, call_service, init_service, TestRequest};
|
||||||
use crate::{web, Error, HttpResponse};
|
use crate::{web, Error, HttpResponse};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -527,7 +527,7 @@ mod tests {
|
|||||||
.route("/test", web::get().to(|| HttpResponse::Ok())),
|
.route("/test", web::get().to(|| HttpResponse::Ok())),
|
||||||
);
|
);
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
||||||
@ -543,7 +543,7 @@ mod tests {
|
|||||||
.wrap(md),
|
.wrap(md),
|
||||||
);
|
);
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
||||||
@ -567,7 +567,7 @@ mod tests {
|
|||||||
.service(web::resource("/test").to(|| HttpResponse::Ok())),
|
.service(web::resource("/test").to(|| HttpResponse::Ok())),
|
||||||
);
|
);
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
||||||
@ -591,7 +591,7 @@ mod tests {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
||||||
|
@ -255,8 +255,8 @@ mod tests {
|
|||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::http::StatusCode;
|
use crate::http::{Method, StatusCode};
|
||||||
use crate::test::{block_on, init_service, TestRequest};
|
use crate::test::{block_on, call_service, init_service, TestRequest};
|
||||||
use crate::{web, App, HttpResponse};
|
use crate::{web, App, HttpResponse};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -300,4 +300,26 @@ mod tests {
|
|||||||
let resp = block_on(srv.call(req)).unwrap();
|
let resp = block_on(srv.call(req)).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_service() {
|
||||||
|
let mut srv = init_service(App::new().configure(|cfg| {
|
||||||
|
cfg.service(
|
||||||
|
web::resource("/test").route(web::get().to(|| HttpResponse::Created())),
|
||||||
|
)
|
||||||
|
.route("/index.html", web::get().to(|| HttpResponse::Ok()));
|
||||||
|
}));
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/test")
|
||||||
|
.method(Method::GET)
|
||||||
|
.to_request();
|
||||||
|
let resp = call_service(&mut srv, req);
|
||||||
|
assert_eq!(resp.status(), StatusCode::CREATED);
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/index.html")
|
||||||
|
.method(Method::GET)
|
||||||
|
.to_request();
|
||||||
|
let resp = call_service(&mut srv, req);
|
||||||
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -848,7 +848,7 @@ mod tests {
|
|||||||
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -859,7 +859,7 @@ mod tests {
|
|||||||
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -879,7 +879,7 @@ mod tests {
|
|||||||
|
|
||||||
assert!(cors.inner.validate_allowed_method(req.head()).is_err());
|
assert!(cors.inner.validate_allowed_method(req.head()).is_err());
|
||||||
assert!(cors.inner.validate_allowed_headers(req.head()).is_err());
|
assert!(cors.inner.validate_allowed_headers(req.head()).is_err());
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
|
|
||||||
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
||||||
@ -899,7 +899,7 @@ mod tests {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&b"*"[..],
|
&b"*"[..],
|
||||||
resp.headers()
|
resp.headers()
|
||||||
@ -945,7 +945,7 @@ mod tests {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -984,7 +984,7 @@ mod tests {
|
|||||||
.method(Method::GET)
|
.method(Method::GET)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -993,7 +993,7 @@ mod tests {
|
|||||||
let mut cors = Cors::new().disable_preflight().finish(test::ok_service());
|
let mut cors = Cors::new().disable_preflight().finish(test::ok_service());
|
||||||
|
|
||||||
let req = TestRequest::default().method(Method::GET).to_srv_request();
|
let req = TestRequest::default().method(Method::GET).to_srv_request();
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert!(resp
|
assert!(resp
|
||||||
.headers()
|
.headers()
|
||||||
.get(header::ACCESS_CONTROL_ALLOW_ORIGIN)
|
.get(header::ACCESS_CONTROL_ALLOW_ORIGIN)
|
||||||
@ -1002,7 +1002,7 @@ mod tests {
|
|||||||
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&b"https://www.example.com"[..],
|
&b"https://www.example.com"[..],
|
||||||
resp.headers()
|
resp.headers()
|
||||||
@ -1029,7 +1029,7 @@ mod tests {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&b"*"[..],
|
&b"*"[..],
|
||||||
resp.headers()
|
resp.headers()
|
||||||
@ -1075,7 +1075,7 @@ mod tests {
|
|||||||
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&b"Accept, Origin"[..],
|
&b"Accept, Origin"[..],
|
||||||
resp.headers().get(header::VARY).unwrap().as_bytes()
|
resp.headers().get(header::VARY).unwrap().as_bytes()
|
||||||
@ -1091,7 +1091,7 @@ mod tests {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.header(header::ACCESS_CONTROL_REQUEST_METHOD, "POST")
|
.header(header::ACCESS_CONTROL_REQUEST_METHOD, "POST")
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
|
|
||||||
let origins_str = resp
|
let origins_str = resp
|
||||||
.headers()
|
.headers()
|
||||||
@ -1115,7 +1115,7 @@ mod tests {
|
|||||||
.method(Method::GET)
|
.method(Method::GET)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&b"https://example.com"[..],
|
&b"https://example.com"[..],
|
||||||
resp.headers()
|
resp.headers()
|
||||||
@ -1128,7 +1128,7 @@ mod tests {
|
|||||||
.method(Method::GET)
|
.method(Method::GET)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&b"https://example.org"[..],
|
&b"https://example.org"[..],
|
||||||
resp.headers()
|
resp.headers()
|
||||||
@ -1151,7 +1151,7 @@ mod tests {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&b"https://example.com"[..],
|
&b"https://example.com"[..],
|
||||||
resp.headers()
|
resp.headers()
|
||||||
@ -1165,7 +1165,7 @@ mod tests {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
let resp = test::call_success(&mut cors, req);
|
let resp = test::call_service(&mut cors, req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&b"https://example.org"[..],
|
&b"https://example.org"[..],
|
||||||
resp.headers()
|
resp.headers()
|
||||||
|
@ -172,7 +172,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let resp = test::call_success(&mut mw, TestRequest::default().to_srv_request());
|
let resp = test::call_service(&mut mw, TestRequest::default().to_srv_request());
|
||||||
assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "0001");
|
assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "0001");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let resp = test::call_success(&mut mw, TestRequest::default().to_srv_request());
|
let resp = test::call_service(&mut mw, TestRequest::default().to_srv_request());
|
||||||
assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "0001");
|
assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "0001");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,15 +500,15 @@ mod tests {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
let resp =
|
let resp =
|
||||||
test::call_success(&mut srv, TestRequest::with_uri("/index").to_request());
|
test::call_service(&mut srv, TestRequest::with_uri("/index").to_request());
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
|
||||||
let resp =
|
let resp =
|
||||||
test::call_success(&mut srv, TestRequest::with_uri("/login").to_request());
|
test::call_service(&mut srv, TestRequest::with_uri("/login").to_request());
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
let c = resp.response().cookies().next().unwrap().to_owned();
|
let c = resp.response().cookies().next().unwrap().to_owned();
|
||||||
|
|
||||||
let resp = test::call_success(
|
let resp = test::call_service(
|
||||||
&mut srv,
|
&mut srv,
|
||||||
TestRequest::with_uri("/index")
|
TestRequest::with_uri("/index")
|
||||||
.cookie(c.clone())
|
.cookie(c.clone())
|
||||||
@ -516,7 +516,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(resp.status(), StatusCode::CREATED);
|
assert_eq!(resp.status(), StatusCode::CREATED);
|
||||||
|
|
||||||
let resp = test::call_success(
|
let resp = test::call_service(
|
||||||
&mut srv,
|
&mut srv,
|
||||||
TestRequest::with_uri("/logout")
|
TestRequest::with_uri("/logout")
|
||||||
.cookie(c.clone())
|
.cookie(c.clone())
|
||||||
|
@ -324,7 +324,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::dev::{ResourceDef, ResourceMap};
|
use crate::dev::{ResourceDef, ResourceMap};
|
||||||
use crate::http::{header, StatusCode};
|
use crate::http::{header, StatusCode};
|
||||||
use crate::test::{call_success, init_service, TestRequest};
|
use crate::test::{call_service, init_service, TestRequest};
|
||||||
use crate::{web, App, HttpResponse};
|
use crate::{web, App, HttpResponse};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -453,7 +453,7 @@ mod tests {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let req = TestRequest::default().to_request();
|
let req = TestRequest::default().to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
|
||||||
let mut srv = init_service(App::new().data(10u32).service(
|
let mut srv = init_service(App::new().data(10u32).service(
|
||||||
@ -467,7 +467,7 @@ mod tests {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let req = TestRequest::default().to_request();
|
let req = TestRequest::default().to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -545,7 +545,7 @@ mod tests {
|
|||||||
|
|
||||||
use crate::http::{header, HeaderValue, Method, StatusCode};
|
use crate::http::{header, HeaderValue, Method, StatusCode};
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
use crate::test::{call_success, init_service, TestRequest};
|
use crate::test::{call_service, init_service, TestRequest};
|
||||||
use crate::{web, App, Error, HttpResponse};
|
use crate::{web, App, Error, HttpResponse};
|
||||||
|
|
||||||
fn md<S, B>(
|
fn md<S, B>(
|
||||||
@ -577,7 +577,7 @@ mod tests {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
||||||
@ -603,7 +603,7 @@ mod tests {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
||||||
@ -618,7 +618,7 @@ mod tests {
|
|||||||
sleep(Duration::from_millis(100)).then(|_| HttpResponse::Ok())
|
sleep(Duration::from_millis(100)).then(|_| HttpResponse::Ok())
|
||||||
})));
|
})));
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,13 +634,13 @@ mod tests {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test")
|
let req = TestRequest::with_uri("/test")
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
.to_request();
|
.to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
|
||||||
let mut srv = init_service(
|
let mut srv = init_service(
|
||||||
@ -654,13 +654,13 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test").to_request();
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test")
|
let req = TestRequest::with_uri("/test")
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
.to_request();
|
.to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/route.rs
12
src/route.rs
@ -422,7 +422,7 @@ mod tests {
|
|||||||
use tokio_timer::sleep;
|
use tokio_timer::sleep;
|
||||||
|
|
||||||
use crate::http::{Method, StatusCode};
|
use crate::http::{Method, StatusCode};
|
||||||
use crate::test::{call_success, init_service, TestRequest};
|
use crate::test::{call_service, init_service, TestRequest};
|
||||||
use crate::{error, web, App, HttpResponse};
|
use crate::{error, web, App, HttpResponse};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -450,31 +450,31 @@ mod tests {
|
|||||||
let req = TestRequest::with_uri("/test")
|
let req = TestRequest::with_uri("/test")
|
||||||
.method(Method::GET)
|
.method(Method::GET)
|
||||||
.to_request();
|
.to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test")
|
let req = TestRequest::with_uri("/test")
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
.to_request();
|
.to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::CREATED);
|
assert_eq!(resp.status(), StatusCode::CREATED);
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test")
|
let req = TestRequest::with_uri("/test")
|
||||||
.method(Method::PUT)
|
.method(Method::PUT)
|
||||||
.to_request();
|
.to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test")
|
let req = TestRequest::with_uri("/test")
|
||||||
.method(Method::DELETE)
|
.method(Method::DELETE)
|
||||||
.to_request();
|
.to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test")
|
let req = TestRequest::with_uri("/test")
|
||||||
.method(Method::HEAD)
|
.method(Method::HEAD)
|
||||||
.to_request();
|
.to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -535,7 +535,7 @@ mod tests {
|
|||||||
use crate::dev::{Body, ResponseBody};
|
use crate::dev::{Body, ResponseBody};
|
||||||
use crate::http::{header, HeaderValue, Method, StatusCode};
|
use crate::http::{header, HeaderValue, Method, StatusCode};
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
use crate::test::{block_on, call_success, init_service, TestRequest};
|
use crate::test::{block_on, call_service, init_service, TestRequest};
|
||||||
use crate::{guard, web, App, Error, HttpRequest, HttpResponse};
|
use crate::{guard, web, App, Error, HttpRequest, HttpResponse};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -912,7 +912,7 @@ mod tests {
|
|||||||
web::resource("/test").route(web::get().to(|| HttpResponse::Ok())),
|
web::resource("/test").route(web::get().to(|| HttpResponse::Ok())),
|
||||||
)));
|
)));
|
||||||
let req = TestRequest::with_uri("/app/test").to_request();
|
let req = TestRequest::with_uri("/app/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
||||||
@ -938,7 +938,7 @@ mod tests {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
let req = TestRequest::with_uri("/app/test").to_request();
|
let req = TestRequest::with_uri("/app/test").to_request();
|
||||||
let resp = call_success(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
resp.headers().get(header::CONTENT_TYPE).unwrap(),
|
||||||
|
@ -137,11 +137,11 @@ where
|
|||||||
/// let req = test::TestRequest::with_uri("/test").to_request();
|
/// let req = test::TestRequest::with_uri("/test").to_request();
|
||||||
///
|
///
|
||||||
/// // Call application
|
/// // Call application
|
||||||
/// let resp = test::call_success(&mut app, req);
|
/// let resp = test::call_service(&mut app, req);
|
||||||
/// assert_eq!(resp.status(), StatusCode::OK);
|
/// assert_eq!(resp.status(), StatusCode::OK);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn call_success<S, R, B, E>(app: &mut S, req: R) -> S::Response
|
pub fn call_service<S, R, B, E>(app: &mut S, req: R) -> S::Response
|
||||||
where
|
where
|
||||||
S: Service<Request = R, Response = ServiceResponse<B>, Error = E>,
|
S: Service<Request = R, Response = ServiceResponse<B>, Error = E>,
|
||||||
E: std::fmt::Debug,
|
E: std::fmt::Debug,
|
||||||
|
Loading…
Reference in New Issue
Block a user