Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Mar 26, 2019
1 parent c7ad677 commit 50c0ddb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 45 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ path = "src/lib.rs"
members = [
".",
"awc",
"actix-http",
"actix-files",
"actix-session",
"actix-web-actors",
Expand Down Expand Up @@ -71,7 +72,7 @@ actix-utils = "0.3.4"
actix-router = "0.1.0"
actix-rt = "0.2.1"
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-config = "0.1.0"
awc = { path = "awc", optional = true }
Expand Down Expand Up @@ -105,8 +106,8 @@ openssl = { version="0.10", optional = true }
# rustls = { version = "^0.15", optional = true }

[dev-dependencies]
actix-http = { git = "https://github.com/actix/actix-http.git", features=["ssl"] }
actix-http-test = { git = "https://github.com/actix/actix-http.git", features=["ssl"] }
actix-http = { path = "actix-http", features=["ssl"] }
actix-http-test = { path = "actix-http/test-server", features=["ssl"] }
rand = "0.6"
env_logger = "0.6"
serde_derive = "1.0"
Expand Down
1 change: 1 addition & 0 deletions actix-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["network-programming", "asynchronous",
license = "MIT/Apache-2.0"
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
edition = "2018"
workspace = ".."

[package.metadata.docs.rs]
features = ["ssl", "fail", "cookie"]
Expand Down
2 changes: 1 addition & 1 deletion actix-http/test-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ actix-http = { path=".." }
actix-service = "0.3.4"
actix-server = "0.4.0"
actix-utils = "0.3.4"
awc = { git = "https://github.com/actix/actix-web.git" }
awc = { path = "../../awc" }

base64 = "0.10"
bytes = "0.4"
Expand Down
6 changes: 3 additions & 3 deletions awc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cookies = ["cookie", "actix-http/cookies"]

[dependencies]
actix-service = "0.3.4"
actix-http = { git = "https://github.com/actix/actix-http.git" }
actix-http = { path = "../actix-http/" }
bytes = "0.4"
futures = "0.1"
log =" 0.4"
Expand All @@ -44,5 +44,5 @@ openssl = { version="0.10", optional = true }
env_logger = "0.6"
mime = "0.3"
actix-rt = "0.2.1"
actix-http = { git = "https://github.com/actix/actix-http.git", features=["ssl"] }
actix-http-test = { git = "https://github.com/actix/actix-http.git", features=["ssl"] }
actix-http = { path = "../actix-http/", features=["ssl"] }
actix-http-test = { path = "../actix-http/test-server/", features=["ssl"] }
11 changes: 4 additions & 7 deletions actix-http/examples/client.rs → examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use actix_http::{client, Error};
use actix_http::Error;
use actix_rt::System;
use bytes::BytesMut;
use futures::{future::lazy, Future, Stream};
Expand All @@ -8,13 +8,10 @@ fn main() -> Result<(), Error> {
env_logger::init();

System::new("test").block_on(lazy(|| {
let mut connector = client::Connector::new().service();

client::ClientRequest::get("https://www.rust-lang.org/") // <- Create request builder
awc::Client::new()
.get("https://www.rust-lang.org/") // <- Create request builder
.header("User-Agent", "Actix-web")
.finish()
.unwrap()
.send(&mut connector) // <- Send http request
.send() // <- Send http request
.from_err()
.and_then(|response| {
// <- server http response
Expand Down
20 changes: 9 additions & 11 deletions tests/test_httpserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@ fn test_start() {
});
let (srv, sys) = rx.recv().unwrap();

let mut connector = test::run_on(|| {
let client = test::run_on(|| {
Ok::<_, ()>(
client::Connector::new()
.timeout(Duration::from_millis(100))
.service(),
awc::Client::build()
.connector(
client::Connector::new()
.timeout(Duration::from_millis(100))
.service(),
)
.finish(),
)
})
.unwrap();
let host = format!("http://{}", addr);

let response = test::block_on(
client::ClientRequest::get(host.clone())
.finish()
.unwrap()
.send(&mut connector),
)
.unwrap();
let response = test::block_on(client.get(host.clone()).send()).unwrap();
assert!(response.status().is_success());

// stop
Expand Down
34 changes: 14 additions & 20 deletions tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ fn test_body() {
)
});

let request = srv.get().finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv.block_on(srv.get().send()).unwrap();
assert!(response.status().is_success());

// read response
Expand All @@ -64,8 +63,7 @@ fn test_body_gzip() {
)
});

let request = srv.get().finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv.block_on(srv.get().send()).unwrap();
assert!(response.status().is_success());

// read response
Expand Down Expand Up @@ -95,8 +93,7 @@ fn test_body_gzip_large() {
)
});

let request = srv.get().finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv.block_on(srv.get().send()).unwrap();
assert!(response.status().is_success());

// read response
Expand Down Expand Up @@ -129,8 +126,7 @@ fn test_body_gzip_large_random() {
)
});

let request = srv.get().finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv.block_on(srv.get().send()).unwrap();
assert!(response.status().is_success());

// read response
Expand Down Expand Up @@ -158,8 +154,7 @@ fn test_body_chunked_implicit() {
)
});

let request = srv.get().finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv.block_on(srv.get().send()).unwrap();
assert!(response.status().is_success());
assert_eq!(
response.headers().get(TRANSFER_ENCODING).unwrap(),
Expand Down Expand Up @@ -190,8 +185,9 @@ fn test_body_br_streaming() {
)
});

let request = srv.get().header(ACCEPT_ENCODING, "br").finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv
.block_on(srv.get().header(ACCEPT_ENCODING, "br").send())
.unwrap();
assert!(response.status().is_success());

// read response
Expand All @@ -212,8 +208,7 @@ fn test_head_binary() {
)))
});

let request = srv.head().finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv.block_on(srv.head().send()).unwrap();
assert!(response.status().is_success());

{
Expand All @@ -239,8 +234,7 @@ fn test_no_chunking() {
))))
});

let request = srv.get().finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv.block_on(srv.get().send()).unwrap();
assert!(response.status().is_success());
assert!(!response.headers().contains_key(TRANSFER_ENCODING));

Expand All @@ -262,8 +256,7 @@ fn test_body_deflate() {
});

// client request
let request = srv.get().finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv.block_on(srv.get().send()).unwrap();
assert!(response.status().is_success());

// read response
Expand All @@ -289,8 +282,9 @@ fn test_body_brotli() {
});

// client request
let request = srv.get().header(ACCEPT_ENCODING, "br").finish().unwrap();
let mut response = srv.send_request(request).unwrap();
let mut response = srv
.block_on(srv.get().header(ACCEPT_ENCODING, "br").send())
.unwrap();
assert!(response.status().is_success());

// read response
Expand Down

0 comments on commit 50c0ddb

Please sign in to comment.