1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-28 07:30:36 +02:00

add test and main macros

This commit is contained in:
Nikolay Kim
2019-11-25 21:49:11 +06:00
parent 1fddd1e75b
commit 4ceac79f2c
25 changed files with 265 additions and 267 deletions

View File

@ -3,7 +3,7 @@ use std::io;
use actix_codec::{BytesCodec, Framed};
use actix_server_config::Io;
use actix_service::{service_fn, Service, ServiceFactory};
use actix_testing::{self as test, TestServer};
use actix_testing::TestServer;
use bytes::Bytes;
use futures::SinkExt;
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
@ -11,8 +11,8 @@ use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
use actix_connect::Connect;
#[cfg(feature = "openssl")]
#[test]
fn test_string() {
#[actix_rt::test]
async fn test_string() {
let srv = TestServer::with(|| {
service_fn(|io: Io<tokio_net::tcp::TcpStream>| {
async {
@ -25,13 +25,13 @@ fn test_string() {
let mut conn = actix_connect::default_connector();
let addr = format!("localhost:{}", srv.port());
let con = test::call_service(&mut conn, addr.into());
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "rustls")]
#[test]
fn test_rustls_string() {
#[actix_rt::test]
async fn test_rustls_string() {
let srv = TestServer::with(|| {
service_fn(|io: Io<tokio_net::tcp::TcpStream>| {
async {
@ -44,7 +44,7 @@ fn test_rustls_string() {
let mut conn = actix_connect::default_connector();
let addr = format!("localhost:{}", srv.port());
let con = test::call_service(&mut conn, addr.into());
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
@ -72,8 +72,8 @@ async fn test_static_str() {
assert!(con.is_err());
}
#[test]
fn test_new_service() {
#[actix_rt::test]
async fn test_new_service() {
let srv = TestServer::with(|| {
service_fn(|io: Io<tokio_net::tcp::TcpStream>| {
async {
@ -84,19 +84,19 @@ fn test_new_service() {
})
});
let resolver = test::block_on(async {
actix_connect::start_resolver(ResolverConfig::default(), ResolverOpts::default())
});
let factory = test::block_on(async { actix_connect::new_connector_factory(resolver) });
let resolver =
actix_connect::start_resolver(ResolverConfig::default(), ResolverOpts::default());
let mut conn = test::block_on(factory.new_service(&())).unwrap();
let con = test::block_on(conn.call(Connect::with("10", srv.addr()))).unwrap();
let factory = actix_connect::new_connector_factory(resolver);
let mut conn = factory.new_service(&()).await.unwrap();
let con = conn.call(Connect::with("10", srv.addr())).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "openssl")]
#[test]
fn test_uri() {
#[actix_rt::test]
async fn test_uri() {
use http::HttpTryFrom;
let srv = TestServer::with(|| {
@ -111,13 +111,13 @@ fn test_uri() {
let mut conn = actix_connect::default_connector();
let addr = http::Uri::try_from(format!("https://localhost:{}", srv.port())).unwrap();
let con = test::call_service(&mut conn, addr.into());
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "rustls")]
#[test]
fn test_rustls_uri() {
#[actix_rt::test]
async fn test_rustls_uri() {
use http::HttpTryFrom;
let srv = TestServer::with(|| {
@ -132,6 +132,6 @@ fn test_rustls_uri() {
let mut conn = actix_connect::default_connector();
let addr = http::Uri::try_from(format!("https://localhost:{}", srv.port())).unwrap();
let con = test::call_service(&mut conn, addr.into());
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}