mirror of
https://github.com/ntex-rs/ntex-extras.git
synced 2025-04-06 06:17:42 +03:00
refactor http-test server
This commit is contained in:
parent
db1d6b7963
commit
4937c9f9c2
17 changed files with 252 additions and 296 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "actix-web-codegen"
|
||||
version = "0.2.0-alpha.2"
|
||||
version = "0.2.0"
|
||||
description = "Actix web proc macros"
|
||||
readme = "README.md"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
|
@ -17,8 +17,6 @@ syn = { version = "^1", features = ["full", "parsing"] }
|
|||
proc-macro2 = "^1"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = { version = "1.0.0-alpha.2" }
|
||||
actix-web = { version = "2.0.0-alpha.2" }
|
||||
actix-http = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-http-test = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-rt = { version = "1.0.0" }
|
||||
actix-web = { version = "2.0.0-alpha.4" }
|
||||
futures = { version = "0.3.1" }
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
use actix_http::HttpService;
|
||||
use actix_http_test::TestServer;
|
||||
use actix_web::{http, web::Path, App, HttpResponse, Responder};
|
||||
use actix_web::{http, test, web::Path, App, HttpResponse, Responder};
|
||||
use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, trace};
|
||||
use futures::{future, Future};
|
||||
|
||||
#[get("/test")]
|
||||
async fn test() -> impl Responder {
|
||||
async fn test_handler() -> impl Responder {
|
||||
HttpResponse::Ok()
|
||||
}
|
||||
|
||||
|
@ -71,14 +69,11 @@ async fn get_param_test(_: Path<String>) -> impl Responder {
|
|||
|
||||
#[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),
|
||||
)
|
||||
.tcp()
|
||||
let srv = test::start(|| {
|
||||
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"));
|
||||
|
@ -96,19 +91,16 @@ async fn test_params() {
|
|||
|
||||
#[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),
|
||||
)
|
||||
.tcp()
|
||||
let srv = test::start(|| {
|
||||
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_handler)
|
||||
});
|
||||
let request = srv.request(http::Method::GET, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
|
@ -151,8 +143,7 @@ async fn test_body() {
|
|||
|
||||
#[actix_rt::test]
|
||||
async fn test_auto_async() {
|
||||
let srv =
|
||||
TestServer::start(|| HttpService::new(App::new().service(auto_async)).tcp());
|
||||
let srv = test::start(|| App::new().service(auto_async));
|
||||
|
||||
let request = srv.request(http::Method::GET, srv.url("/test"));
|
||||
let response = request.send().await.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue