1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

update tests

This commit is contained in:
Nikolay Kim 2019-03-26 12:31:51 -07:00
parent c7ad677804
commit 50c0ddb3cd
7 changed files with 36 additions and 45 deletions

View File

@ -28,6 +28,7 @@ path = "src/lib.rs"
members = [ members = [
".", ".",
"awc", "awc",
"actix-http",
"actix-files", "actix-files",
"actix-session", "actix-session",
"actix-web-actors", "actix-web-actors",
@ -71,7 +72,7 @@ actix-utils = "0.3.4"
actix-router = "0.1.0" actix-router = "0.1.0"
actix-rt = "0.2.1" actix-rt = "0.2.1"
actix-web-codegen = { path="actix-web-codegen" } actix-web-codegen = { path="actix-web-codegen" }
actix-http = { git = "https://github.com/actix/actix-http.git", features=["fail"] } actix-http = { path = "actix-http", features=["fail"] }
actix-server = "0.4.1" actix-server = "0.4.1"
actix-server-config = "0.1.0" actix-server-config = "0.1.0"
awc = { path = "awc", optional = true } awc = { path = "awc", optional = true }
@ -105,8 +106,8 @@ openssl = { version="0.10", optional = true }
# rustls = { version = "^0.15", optional = true } # rustls = { version = "^0.15", optional = true }
[dev-dependencies] [dev-dependencies]
actix-http = { git = "https://github.com/actix/actix-http.git", features=["ssl"] } actix-http = { path = "actix-http", features=["ssl"] }
actix-http-test = { git = "https://github.com/actix/actix-http.git", features=["ssl"] } actix-http-test = { path = "actix-http/test-server", features=["ssl"] }
rand = "0.6" rand = "0.6"
env_logger = "0.6" env_logger = "0.6"
serde_derive = "1.0" serde_derive = "1.0"

View File

@ -14,6 +14,7 @@ categories = ["network-programming", "asynchronous",
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"] exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
edition = "2018" edition = "2018"
workspace = ".."
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["ssl", "fail", "cookie"] features = ["ssl", "fail", "cookie"]

View File

@ -38,7 +38,7 @@ actix-http = { path=".." }
actix-service = "0.3.4" actix-service = "0.3.4"
actix-server = "0.4.0" actix-server = "0.4.0"
actix-utils = "0.3.4" actix-utils = "0.3.4"
awc = { git = "https://github.com/actix/actix-web.git" } awc = { path = "../../awc" }
base64 = "0.10" base64 = "0.10"
bytes = "0.4" bytes = "0.4"

View File

@ -28,7 +28,7 @@ cookies = ["cookie", "actix-http/cookies"]
[dependencies] [dependencies]
actix-service = "0.3.4" actix-service = "0.3.4"
actix-http = { git = "https://github.com/actix/actix-http.git" } actix-http = { path = "../actix-http/" }
bytes = "0.4" bytes = "0.4"
futures = "0.1" futures = "0.1"
log =" 0.4" log =" 0.4"
@ -44,5 +44,5 @@ openssl = { version="0.10", optional = true }
env_logger = "0.6" env_logger = "0.6"
mime = "0.3" mime = "0.3"
actix-rt = "0.2.1" actix-rt = "0.2.1"
actix-http = { git = "https://github.com/actix/actix-http.git", features=["ssl"] } actix-http = { path = "../actix-http/", features=["ssl"] }
actix-http-test = { git = "https://github.com/actix/actix-http.git", features=["ssl"] } actix-http-test = { path = "../actix-http/test-server/", features=["ssl"] }

View File

@ -1,4 +1,4 @@
use actix_http::{client, Error}; use actix_http::Error;
use actix_rt::System; use actix_rt::System;
use bytes::BytesMut; use bytes::BytesMut;
use futures::{future::lazy, Future, Stream}; use futures::{future::lazy, Future, Stream};
@ -8,13 +8,10 @@ fn main() -> Result<(), Error> {
env_logger::init(); env_logger::init();
System::new("test").block_on(lazy(|| { System::new("test").block_on(lazy(|| {
let mut connector = client::Connector::new().service(); awc::Client::new()
.get("https://www.rust-lang.org/") // <- Create request builder
client::ClientRequest::get("https://www.rust-lang.org/") // <- Create request builder
.header("User-Agent", "Actix-web") .header("User-Agent", "Actix-web")
.finish() .send() // <- Send http request
.unwrap()
.send(&mut connector) // <- Send http request
.from_err() .from_err()
.and_then(|response| { .and_then(|response| {
// <- server http response // <- server http response

View File

@ -48,23 +48,21 @@ fn test_start() {
}); });
let (srv, sys) = rx.recv().unwrap(); let (srv, sys) = rx.recv().unwrap();
let mut connector = test::run_on(|| { let client = test::run_on(|| {
Ok::<_, ()>( Ok::<_, ()>(
client::Connector::new() awc::Client::build()
.timeout(Duration::from_millis(100)) .connector(
.service(), client::Connector::new()
.timeout(Duration::from_millis(100))
.service(),
)
.finish(),
) )
}) })
.unwrap(); .unwrap();
let host = format!("http://{}", addr); let host = format!("http://{}", addr);
let response = test::block_on( let response = test::block_on(client.get(host.clone()).send()).unwrap();
client::ClientRequest::get(host.clone())
.finish()
.unwrap()
.send(&mut connector),
)
.unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
// stop // stop

View File

@ -45,8 +45,7 @@ fn test_body() {
) )
}); });
let request = srv.get().finish().unwrap(); let mut response = srv.block_on(srv.get().send()).unwrap();
let mut response = srv.send_request(request).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
// read response // read response
@ -64,8 +63,7 @@ fn test_body_gzip() {
) )
}); });
let request = srv.get().finish().unwrap(); let mut response = srv.block_on(srv.get().send()).unwrap();
let mut response = srv.send_request(request).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
// read response // read response
@ -95,8 +93,7 @@ fn test_body_gzip_large() {
) )
}); });
let request = srv.get().finish().unwrap(); let mut response = srv.block_on(srv.get().send()).unwrap();
let mut response = srv.send_request(request).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
// read response // read response
@ -129,8 +126,7 @@ fn test_body_gzip_large_random() {
) )
}); });
let request = srv.get().finish().unwrap(); let mut response = srv.block_on(srv.get().send()).unwrap();
let mut response = srv.send_request(request).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
// read response // read response
@ -158,8 +154,7 @@ fn test_body_chunked_implicit() {
) )
}); });
let request = srv.get().finish().unwrap(); let mut response = srv.block_on(srv.get().send()).unwrap();
let mut response = srv.send_request(request).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
assert_eq!( assert_eq!(
response.headers().get(TRANSFER_ENCODING).unwrap(), response.headers().get(TRANSFER_ENCODING).unwrap(),
@ -190,8 +185,9 @@ fn test_body_br_streaming() {
) )
}); });
let request = srv.get().header(ACCEPT_ENCODING, "br").finish().unwrap(); let mut response = srv
let mut response = srv.send_request(request).unwrap(); .block_on(srv.get().header(ACCEPT_ENCODING, "br").send())
.unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
// read response // read response
@ -212,8 +208,7 @@ fn test_head_binary() {
))) )))
}); });
let request = srv.head().finish().unwrap(); let mut response = srv.block_on(srv.head().send()).unwrap();
let mut response = srv.send_request(request).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
{ {
@ -239,8 +234,7 @@ fn test_no_chunking() {
)))) ))))
}); });
let request = srv.get().finish().unwrap(); let mut response = srv.block_on(srv.get().send()).unwrap();
let mut response = srv.send_request(request).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
assert!(!response.headers().contains_key(TRANSFER_ENCODING)); assert!(!response.headers().contains_key(TRANSFER_ENCODING));
@ -262,8 +256,7 @@ fn test_body_deflate() {
}); });
// client request // client request
let request = srv.get().finish().unwrap(); let mut response = srv.block_on(srv.get().send()).unwrap();
let mut response = srv.send_request(request).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
// read response // read response
@ -289,8 +282,9 @@ fn test_body_brotli() {
}); });
// client request // client request
let request = srv.get().header(ACCEPT_ENCODING, "br").finish().unwrap(); let mut response = srv
let mut response = srv.send_request(request).unwrap(); .block_on(srv.get().header(ACCEPT_ENCODING, "br").send())
.unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
// read response // read response