mirror of
https://github.com/ntex-rs/ntex-extras.git
synced 2025-04-05 22:07:40 +03:00
use actix_rt::test for test setup
This commit is contained in:
parent
c1c44a7dd6
commit
4dc31aac93
80 changed files with 6502 additions and 7237 deletions
|
@ -17,6 +17,7 @@ syn = { version = "^1", features = ["full", "parsing"] }
|
|||
proc-macro2 = "^1"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = { version = "1.0.0-alpha.1" }
|
||||
actix-web = { version = "2.0.0-alpha.1" }
|
||||
actix-http = { version = "0.3.0-alpha.1", features=["openssl"] }
|
||||
actix-http-test = { version = "0.3.0-alpha.1", features=["openssl"] }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use actix_http::HttpService;
|
||||
use actix_http_test::{block_on, TestServer};
|
||||
use actix_http_test::TestServer;
|
||||
use actix_web::{http, web::Path, App, HttpResponse, Responder};
|
||||
use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, trace};
|
||||
use futures::{future, Future};
|
||||
|
@ -69,95 +69,89 @@ async fn get_param_test(_: Path<String>) -> impl Responder {
|
|||
HttpResponse::Ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_params() {
|
||||
block_on(async {
|
||||
let srv = TestServer::start(|| {
|
||||
HttpService::new(
|
||||
App::new()
|
||||
.service(get_param_test)
|
||||
.service(put_param_test)
|
||||
.service(delete_param_test),
|
||||
)
|
||||
});
|
||||
#[actix_rt::test]
|
||||
async fn test_params() {
|
||||
let srv = TestServer::start(|| {
|
||||
HttpService::new(
|
||||
App::new()
|
||||
.service(get_param_test)
|
||||
.service(put_param_test)
|
||||
.service(delete_param_test),
|
||||
)
|
||||
});
|
||||
|
||||
let request = srv.request(http::Method::GET, srv.url("/test/it"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::OK);
|
||||
let request = srv.request(http::Method::GET, srv.url("/test/it"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::OK);
|
||||
|
||||
let request = srv.request(http::Method::PUT, srv.url("/test/it"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::CREATED);
|
||||
let request = srv.request(http::Method::PUT, srv.url("/test/it"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::CREATED);
|
||||
|
||||
let request = srv.request(http::Method::DELETE, srv.url("/test/it"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::NO_CONTENT);
|
||||
})
|
||||
let request = srv.request(http::Method::DELETE, srv.url("/test/it"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::NO_CONTENT);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_body() {
|
||||
block_on(async {
|
||||
let srv = TestServer::start(|| {
|
||||
HttpService::new(
|
||||
App::new()
|
||||
.service(post_test)
|
||||
.service(put_test)
|
||||
.service(head_test)
|
||||
.service(connect_test)
|
||||
.service(options_test)
|
||||
.service(trace_test)
|
||||
.service(patch_test)
|
||||
.service(test),
|
||||
)
|
||||
});
|
||||
let request = srv.request(http::Method::GET, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
#[actix_rt::test]
|
||||
async fn test_body() {
|
||||
let srv = TestServer::start(|| {
|
||||
HttpService::new(
|
||||
App::new()
|
||||
.service(post_test)
|
||||
.service(put_test)
|
||||
.service(head_test)
|
||||
.service(connect_test)
|
||||
.service(options_test)
|
||||
.service(trace_test)
|
||||
.service(patch_test)
|
||||
.service(test),
|
||||
)
|
||||
});
|
||||
let request = srv.request(http::Method::GET, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.request(http::Method::HEAD, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
let request = srv.request(http::Method::HEAD, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.request(http::Method::CONNECT, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
let request = srv.request(http::Method::CONNECT, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.request(http::Method::OPTIONS, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
let request = srv.request(http::Method::OPTIONS, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.request(http::Method::TRACE, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
let request = srv.request(http::Method::TRACE, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.request(http::Method::PATCH, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
let request = srv.request(http::Method::PATCH, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.request(http::Method::PUT, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(response.status(), http::StatusCode::CREATED);
|
||||
let request = srv.request(http::Method::PUT, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(response.status(), http::StatusCode::CREATED);
|
||||
|
||||
let request = srv.request(http::Method::POST, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(response.status(), http::StatusCode::NO_CONTENT);
|
||||
let request = srv.request(http::Method::POST, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(response.status(), http::StatusCode::NO_CONTENT);
|
||||
|
||||
let request = srv.request(http::Method::GET, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
})
|
||||
let request = srv.request(http::Method::GET, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_auto_async() {
|
||||
block_on(async {
|
||||
let srv = TestServer::start(|| HttpService::new(App::new().service(auto_async)));
|
||||
#[actix_rt::test]
|
||||
async fn test_auto_async() {
|
||||
let srv = TestServer::start(|| HttpService::new(App::new().service(auto_async)));
|
||||
|
||||
let request = srv.request(http::Method::GET, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
})
|
||||
let request = srv.request(http::Method::GET, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue