mirror of
https://github.com/fafhrd91/actix-net
synced 2025-06-28 07:30:36 +02:00
use actix-testing instead of test server
This commit is contained in:
@ -57,5 +57,5 @@ webpki = { version = "0.19", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
bytes = "0.4"
|
||||
actix-test-server = { version="0.2.2", features=["ssl"] }
|
||||
actix-testing = { version="0.1.0" }
|
||||
actix-server-config = "0.1.0"
|
||||
|
@ -1,13 +1,12 @@
|
||||
use actix_codec::{BytesCodec, Framed};
|
||||
use actix_server_config::Io;
|
||||
use actix_service::{service_fn, NewService, Service};
|
||||
use actix_test_server::TestServer;
|
||||
use actix_testing::{self as test, TestServer};
|
||||
use bytes::Bytes;
|
||||
use futures::{future::lazy, Future, Sink};
|
||||
use http::{HttpTryFrom, Uri};
|
||||
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
||||
|
||||
use actix_connect::{default_connector, Connect};
|
||||
use actix_connect::Connect;
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
#[test]
|
||||
@ -44,7 +43,7 @@ fn test_rustls_string() {
|
||||
}
|
||||
#[test]
|
||||
fn test_static_str() {
|
||||
let mut srv = TestServer::with(|| {
|
||||
let srv = TestServer::with(|| {
|
||||
service_fn(|io: Io<tokio_tcp::TcpStream>| {
|
||||
Framed::new(io.into_parts().0, BytesCodec)
|
||||
.send(Bytes::from_static(b"test"))
|
||||
@ -52,33 +51,29 @@ fn test_static_str() {
|
||||
})
|
||||
});
|
||||
|
||||
let resolver = srv
|
||||
.block_on(lazy(
|
||||
|| Ok::<_, ()>(actix_connect::start_default_resolver()),
|
||||
))
|
||||
.unwrap();
|
||||
let mut conn = srv
|
||||
.block_on(lazy(|| {
|
||||
Ok::<_, ()>(actix_connect::new_connector(resolver.clone()))
|
||||
}))
|
||||
.unwrap();
|
||||
let resolver = test::block_on(lazy(
|
||||
|| Ok::<_, ()>(actix_connect::start_default_resolver()),
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let con = srv
|
||||
.block_on(conn.call(Connect::with("10", srv.addr())))
|
||||
.unwrap();
|
||||
let mut conn = test::block_on(lazy(|| {
|
||||
Ok::<_, ()>(actix_connect::new_connector(resolver.clone()))
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
let con = test::block_on(conn.call(Connect::with("10", srv.addr()))).unwrap();
|
||||
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
||||
|
||||
let connect = Connect::new(srv.host().to_owned());
|
||||
let mut conn = srv
|
||||
.block_on(lazy(|| Ok::<_, ()>(actix_connect::new_connector(resolver))))
|
||||
.unwrap();
|
||||
let con = srv.block_on(conn.call(connect));
|
||||
let mut conn =
|
||||
test::block_on(lazy(|| Ok::<_, ()>(actix_connect::new_connector(resolver)))).unwrap();
|
||||
let con = test::block_on(conn.call(connect));
|
||||
assert!(con.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_service() {
|
||||
let mut srv = TestServer::with(|| {
|
||||
let srv = TestServer::with(|| {
|
||||
service_fn(|io: Io<tokio_tcp::TcpStream>| {
|
||||
Framed::new(io.into_parts().0, BytesCodec)
|
||||
.send(Bytes::from_static(b"test"))
|
||||
@ -86,24 +81,20 @@ fn test_new_service() {
|
||||
})
|
||||
});
|
||||
|
||||
let resolver = srv
|
||||
.block_on(lazy(|| {
|
||||
Ok::<_, ()>(actix_connect::start_resolver(
|
||||
ResolverConfig::default(),
|
||||
ResolverOpts::default(),
|
||||
))
|
||||
}))
|
||||
.unwrap();
|
||||
let factory = srv
|
||||
.block_on(lazy(|| {
|
||||
Ok::<_, ()>(actix_connect::new_connector_factory(resolver))
|
||||
}))
|
||||
.unwrap();
|
||||
let resolver = test::block_on(lazy(|| {
|
||||
Ok::<_, ()>(actix_connect::start_resolver(
|
||||
ResolverConfig::default(),
|
||||
ResolverOpts::default(),
|
||||
))
|
||||
}))
|
||||
.unwrap();
|
||||
let factory = test::block_on(lazy(|| {
|
||||
Ok::<_, ()>(actix_connect::new_connector_factory(resolver))
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
let mut conn = srv.block_on(factory.new_service(&())).unwrap();
|
||||
let con = srv
|
||||
.block_on(conn.call(Connect::with("10", srv.addr())))
|
||||
.unwrap();
|
||||
let mut conn = test::block_on(factory.new_service(&())).unwrap();
|
||||
let con = test::block_on(conn.call(Connect::with("10", srv.addr()))).unwrap();
|
||||
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
||||
}
|
||||
|
||||
@ -120,7 +111,7 @@ fn test_uri() {
|
||||
|
||||
let mut conn = default_connector();
|
||||
let addr = Uri::try_from(format!("https://localhost:{}", srv.port())).unwrap();
|
||||
let con = srv.run_on(move || conn.call(addr.into())).unwrap();
|
||||
let con = test::run_on(move || conn.call(addr.into())).unwrap();
|
||||
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
||||
}
|
||||
|
||||
@ -137,6 +128,6 @@ fn test_rustls_uri() {
|
||||
|
||||
let mut conn = default_connector();
|
||||
let addr = Uri::try_from(format!("https://localhost:{}", srv.port())).unwrap();
|
||||
let con = srv.run_on(move || conn.call(addr.into())).unwrap();
|
||||
let con = test::run_on(move || conn.call(addr.into())).unwrap();
|
||||
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
||||
}
|
||||
|
Reference in New Issue
Block a user