1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 23:51:06 +01:00

Rename test::call_success to test::call_service

This commit is contained in:
Nikolay Kim 2019-04-15 07:44:07 -07:00
parent 09cdf1e302
commit 7a28b32f6d
11 changed files with 74 additions and 50 deletions

View File

@ -11,6 +11,8 @@
* Rename `RouterConfig` to `ServiceConfig`
* Rename `test::call_success` to `test::call_service`
### Fixed
* Fixed `TestRequest::app_data()`

View File

@ -436,7 +436,7 @@ mod tests {
use super::*;
use crate::http::{header, HeaderValue, Method, StatusCode};
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};
#[test]
@ -527,7 +527,7 @@ mod tests {
.route("/test", web::get().to(|| HttpResponse::Ok())),
);
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.headers().get(header::CONTENT_TYPE).unwrap(),
@ -543,7 +543,7 @@ mod tests {
.wrap(md),
);
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.headers().get(header::CONTENT_TYPE).unwrap(),
@ -567,7 +567,7 @@ mod tests {
.service(web::resource("/test").to(|| HttpResponse::Ok())),
);
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.headers().get(header::CONTENT_TYPE).unwrap(),
@ -591,7 +591,7 @@ mod tests {
}),
);
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.headers().get(header::CONTENT_TYPE).unwrap(),

View File

@ -255,8 +255,8 @@ mod tests {
use actix_service::Service;
use super::*;
use crate::http::StatusCode;
use crate::test::{block_on, init_service, TestRequest};
use crate::http::{Method, StatusCode};
use crate::test::{block_on, call_service, init_service, TestRequest};
use crate::{web, App, HttpResponse};
#[test]
@ -300,4 +300,26 @@ mod tests {
let resp = block_on(srv.call(req)).unwrap();
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);
}
}

View File

@ -848,7 +848,7 @@ mod tests {
let req = TestRequest::with_header("Origin", "https://www.example.com")
.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);
}
@ -859,7 +859,7 @@ mod tests {
let req = TestRequest::with_header("Origin", "https://www.example.com")
.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);
}
@ -879,7 +879,7 @@ mod tests {
assert!(cors.inner.validate_allowed_method(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);
let req = TestRequest::with_header("Origin", "https://www.example.com")
@ -899,7 +899,7 @@ mod tests {
.method(Method::OPTIONS)
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
assert_eq!(
&b"*"[..],
resp.headers()
@ -945,7 +945,7 @@ mod tests {
.method(Method::OPTIONS)
.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);
}
@ -984,7 +984,7 @@ mod tests {
.method(Method::GET)
.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);
}
@ -993,7 +993,7 @@ mod tests {
let mut cors = Cors::new().disable_preflight().finish(test::ok_service());
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
.headers()
.get(header::ACCESS_CONTROL_ALLOW_ORIGIN)
@ -1002,7 +1002,7 @@ mod tests {
let req = TestRequest::with_header("Origin", "https://www.example.com")
.method(Method::OPTIONS)
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
assert_eq!(
&b"https://www.example.com"[..],
resp.headers()
@ -1029,7 +1029,7 @@ mod tests {
.method(Method::OPTIONS)
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
assert_eq!(
&b"*"[..],
resp.headers()
@ -1075,7 +1075,7 @@ mod tests {
let req = TestRequest::with_header("Origin", "https://www.example.com")
.method(Method::OPTIONS)
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
assert_eq!(
&b"Accept, Origin"[..],
resp.headers().get(header::VARY).unwrap().as_bytes()
@ -1091,7 +1091,7 @@ mod tests {
.method(Method::OPTIONS)
.header(header::ACCESS_CONTROL_REQUEST_METHOD, "POST")
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
let origins_str = resp
.headers()
@ -1115,7 +1115,7 @@ mod tests {
.method(Method::GET)
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
assert_eq!(
&b"https://example.com"[..],
resp.headers()
@ -1128,7 +1128,7 @@ mod tests {
.method(Method::GET)
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
assert_eq!(
&b"https://example.org"[..],
resp.headers()
@ -1151,7 +1151,7 @@ mod tests {
.method(Method::OPTIONS)
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
assert_eq!(
&b"https://example.com"[..],
resp.headers()
@ -1165,7 +1165,7 @@ mod tests {
.method(Method::OPTIONS)
.to_srv_request();
let resp = test::call_success(&mut cors, req);
let resp = test::call_service(&mut cors, req);
assert_eq!(
&b"https://example.org"[..],
resp.headers()

View File

@ -172,7 +172,7 @@ mod tests {
)
.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");
}
@ -198,7 +198,7 @@ mod tests {
)
.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");
}
}

View File

@ -500,15 +500,15 @@ mod tests {
})),
);
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);
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);
let c = resp.response().cookies().next().unwrap().to_owned();
let resp = test::call_success(
let resp = test::call_service(
&mut srv,
TestRequest::with_uri("/index")
.cookie(c.clone())
@ -516,7 +516,7 @@ mod tests {
);
assert_eq!(resp.status(), StatusCode::CREATED);
let resp = test::call_success(
let resp = test::call_service(
&mut srv,
TestRequest::with_uri("/logout")
.cookie(c.clone())

View File

@ -324,7 +324,7 @@ mod tests {
use super::*;
use crate::dev::{ResourceDef, ResourceMap};
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};
#[test]
@ -453,7 +453,7 @@ mod tests {
));
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);
let mut srv = init_service(App::new().data(10u32).service(
@ -467,7 +467,7 @@ mod tests {
));
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);
}
}

View File

@ -545,7 +545,7 @@ mod tests {
use crate::http::{header, HeaderValue, Method, StatusCode};
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};
fn md<S, B>(
@ -577,7 +577,7 @@ mod tests {
),
);
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.headers().get(header::CONTENT_TYPE).unwrap(),
@ -603,7 +603,7 @@ mod tests {
),
);
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.headers().get(header::CONTENT_TYPE).unwrap(),
@ -618,7 +618,7 @@ mod tests {
sleep(Duration::from_millis(100)).then(|_| HttpResponse::Ok())
})));
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);
}
@ -634,13 +634,13 @@ mod tests {
}),
);
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);
let req = TestRequest::with_uri("/test")
.method(Method::POST)
.to_request();
let resp = call_success(&mut srv, req);
let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
let mut srv = init_service(
@ -654,13 +654,13 @@ mod tests {
);
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);
let req = TestRequest::with_uri("/test")
.method(Method::POST)
.to_request();
let resp = call_success(&mut srv, req);
let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
}

View File

@ -422,7 +422,7 @@ mod tests {
use tokio_timer::sleep;
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};
#[test]
@ -450,31 +450,31 @@ mod tests {
let req = TestRequest::with_uri("/test")
.method(Method::GET)
.to_request();
let resp = call_success(&mut srv, req);
let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::OK);
let req = TestRequest::with_uri("/test")
.method(Method::POST)
.to_request();
let resp = call_success(&mut srv, req);
let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::CREATED);
let req = TestRequest::with_uri("/test")
.method(Method::PUT)
.to_request();
let resp = call_success(&mut srv, req);
let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let req = TestRequest::with_uri("/test")
.method(Method::DELETE)
.to_request();
let resp = call_success(&mut srv, req);
let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
let req = TestRequest::with_uri("/test")
.method(Method::HEAD)
.to_request();
let resp = call_success(&mut srv, req);
let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
}
}

View File

@ -535,7 +535,7 @@ mod tests {
use crate::dev::{Body, ResponseBody};
use crate::http::{header, HeaderValue, Method, StatusCode};
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};
#[test]
@ -912,7 +912,7 @@ mod tests {
web::resource("/test").route(web::get().to(|| HttpResponse::Ok())),
)));
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.headers().get(header::CONTENT_TYPE).unwrap(),
@ -938,7 +938,7 @@ mod tests {
),
);
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.headers().get(header::CONTENT_TYPE).unwrap(),

View File

@ -137,11 +137,11 @@ where
/// let req = test::TestRequest::with_uri("/test").to_request();
///
/// // Call application
/// let resp = test::call_success(&mut app, req);
/// let resp = test::call_service(&mut app, req);
/// 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
S: Service<Request = R, Response = ServiceResponse<B>, Error = E>,
E: std::fmt::Debug,