More tests (#159)

* More tests
* clippy tests
This commit is contained in:
Nikolay Kim 2023-01-08 17:45:22 +06:00 committed by GitHub
parent f47e830cfb
commit 15019a2a43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 196 additions and 118 deletions

View file

@ -975,6 +975,7 @@ mod tests {
use crate::{BytesMut, BytesVec};
#[test]
#[allow(clippy::needless_borrow)]
fn buf_mut_tests() {
let mut buf = vec![];
buf.put_u8(0x01);

View file

@ -4071,6 +4071,7 @@ mod tests {
}
#[test]
#[allow(clippy::len_zero)]
fn bytes() {
let mut b = Bytes::from(LONG.to_vec());
b.clear();
@ -4113,12 +4114,12 @@ mod tests {
#[test]
fn bytes_vec() {
let bv = BytesVec::copy_from_slice(&LONG[..]);
let bv = BytesVec::copy_from_slice(LONG);
// SharedVec size is 32
assert_eq!(bv.capacity(), mem::size_of::<SharedVec>() * 9);
assert_eq!(bv.len(), 263);
assert_eq!(bv.as_ref().len(), 263);
assert_eq!(bv.as_ref(), &LONG[..]);
assert_eq!(bv.as_ref(), LONG);
let mut bv = BytesVec::copy_from_slice(&b"hello"[..]);
assert_eq!(bv.capacity(), mem::size_of::<SharedVec>());

View file

@ -177,7 +177,7 @@ fn inline() {
a.truncate(8);
assert!(a.is_inline());
let mut a = BytesVec::copy_from_slice(&vec![b'*'; 35]).freeze();
let mut a = BytesVec::copy_from_slice(vec![b'*'; 35]).freeze();
let b = a.split_to(8);
assert!(b.is_inline());
}
@ -444,6 +444,12 @@ fn split_off_to_at_gt_len() {
}
#[test]
#[allow(
clippy::cmp_owned,
clippy::redundant_slicing,
clippy::iter_cloned_collect,
clippy::needless_borrow
)]
fn fns_defined_for_bytes() {
let mut bytes = Bytes::from(&b"hello world"[..]);
let _ = bytes.as_ptr();
@ -452,7 +458,7 @@ fn fns_defined_for_bytes() {
assert!(bytes > "g");
assert!(bytes > "g".to_string());
assert!(bytes > "g".as_bytes().to_vec());
assert!(bytes > Bytes::from(&"g"[..]));
assert!(bytes > Bytes::from("g"));
assert!("g" > bytes);
assert!("g".to_string() > bytes);
assert!("g".as_bytes().to_vec() > bytes);
@ -494,6 +500,11 @@ fn fns_defined_for_bytes() {
}
#[test]
#[allow(
clippy::iter_cloned_collect,
clippy::redundant_slicing,
clippy::needless_borrow
)]
fn fns_defined_for_bytes_mut() {
let mut bytes = BytesMut::from(&b"hello world"[..]);
let _ = bytes.as_ptr();
@ -555,6 +566,7 @@ fn fns_defined_for_bytes_mut() {
}
#[test]
#[allow(clippy::redundant_slicing)]
fn fns_defined_for_bytes_vec() {
// BytesVec
let mut bytes = BytesVec::copy_from_slice(&b"hello world"[..]);
@ -572,13 +584,13 @@ fn fns_defined_for_bytes_vec() {
assert_eq!("hello world", bytes);
assert_eq!("hello world".as_bytes().to_vec(), bytes);
assert_eq!("hello world".to_string(), bytes);
assert_eq!(&"hello world"[..], bytes);
assert_eq!("hello world", bytes);
// Iterator
let v: Vec<u8> = (&bytes).iter().cloned().collect();
let v: Vec<u8> = bytes.iter().cloned().collect();
assert_eq!(&v[..], bytes);
let v: Vec<u8> = bytes.as_ref().iter().cloned().collect();
let v: Vec<u8> = bytes.as_ref().to_vec();
assert_eq!(&v[..], bytes);
let v: Vec<u8> = bytes.iter().cloned().collect();
@ -978,7 +990,7 @@ fn bytes_vec() {
bytes.with_bytes_mut(|buf| {
*buf = BytesMut::from(b"12345".to_vec());
});
assert_eq!(bytes, &"12345"[..]);
assert_eq!(bytes, "12345");
}
#[test]

View file

@ -44,6 +44,7 @@ mod tests {
use super::*;
#[test]
#[allow(clippy::redundant_clone)]
fn connect_error_clone() {
let _ =
ConnectError::Resolver(io::Error::new(io::ErrorKind::Other, "test")).clone();

View file

@ -271,9 +271,7 @@ mod tests {
assert_eq!(*connect.get_ref(), "www.rust-lang.org");
connect = connect.set_port(80);
assert_eq!(connect.port(), 80);
let addrs: Vec<_> = connect.addrs().collect();
assert!(addrs.is_empty());
assert!(connect.addrs().next().is_none());
let addr: SocketAddr = "127.0.0.1:8080".parse().unwrap();
connect = connect.set_addrs(vec![addr]);
@ -292,9 +290,7 @@ mod tests {
assert_eq!(addrs.len(), 2);
assert!(addrs.contains(&addr));
assert!(addrs.contains(&addr2));
let addrs: Vec<_> = connect.addrs().collect();
assert!(addrs.is_empty());
assert!(connect.addrs().next().is_none());
connect = connect.set_addrs(vec![addr]);
assert_eq!(format!("{}", connect), "www.rust-lang.org:80");

View file

@ -576,6 +576,7 @@ mod tests {
}
#[test]
#[allow(clippy::needless_borrow)]
fn test_basics() {
let m = HeaderMap::default();
assert!(m.is_empty());
@ -599,8 +600,7 @@ mod tests {
HeaderValue::from_static("text")
);
let keys: Vec<_> = m.keys().collect();
assert!(keys.contains(&&CONTENT_TYPE));
assert!(m.keys().any(|x| x == CONTENT_TYPE));
m.remove("content-type");
assert!(m.is_empty());
}

View file

@ -751,6 +751,7 @@ mod tests {
use super::*;
#[test]
#[allow(clippy::op_ref, clippy::cmp_owned, deprecated)]
fn test_basics() {
assert!(HeaderValue::from_str("").unwrap().is_empty());

View file

@ -17,7 +17,7 @@ path = "src/lib.rs"
[dependencies]
ntex-codec = "0.6.2"
ntex-bytes = "0.1.14"
ntex-bytes = "0.1.18"
ntex-util = "0.2.0"
ntex-service = "1.0.0"

View file

@ -541,7 +541,7 @@ mod tests {
assert!(st
.io()
.encode(Bytes::from_static(b"test"), &mut BytesCodec)
.encode(Bytes::from_static(b"test"), &BytesCodec)
.is_ok());
let buf = client.read().await.unwrap();
assert_eq!(buf, Bytes::from_static(b"test"));
@ -567,10 +567,7 @@ mod tests {
);
state
.io()
.encode(
Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"),
&mut BytesCodec,
)
.encode(Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"), &BytesCodec)
.unwrap();
spawn(async move {
let _ = disp.await;
@ -619,10 +616,7 @@ mod tests {
let (disp, state) = Dispatcher::debug(server, BytesCodec, Srv(counter.clone()));
state
.io()
.encode(
Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"),
&mut BytesCodec,
)
.encode(Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"), &BytesCodec)
.unwrap();
spawn(async move {
let _ = disp.await;
@ -764,7 +758,6 @@ mod tests {
assert_eq!(&data.lock().unwrap().borrow()[..], &[0, 1]);
}
#[cfg(not(target_os = "macos"))]
#[ntex::test]
async fn test_unhandled_data() {
let handled = Arc::new(AtomicBool::new(false));

View file

@ -2,8 +2,7 @@ use std::{any, io, task::Context, task::Poll};
use ntex_bytes::BytesVec;
use super::io::Flags;
use super::{Filter, IoRef, ReadStatus, WriteStatus};
use super::{io::Flags, Filter, IoRef, ReadStatus, WriteStatus};
/// Default `Io` filter
pub struct Base(IoRef);
@ -117,36 +116,45 @@ impl NullFilter {
}
impl Filter for NullFilter {
#[inline]
fn query(&self, _: any::TypeId) -> Option<Box<dyn any::Any>> {
None
}
#[inline]
fn poll_shutdown(&self) -> Poll<io::Result<()>> {
Poll::Ready(Ok(()))
}
#[inline]
fn poll_read_ready(&self, _: &mut Context<'_>) -> Poll<ReadStatus> {
Poll::Ready(ReadStatus::Terminate)
}
#[inline]
fn poll_write_ready(&self, _: &mut Context<'_>) -> Poll<WriteStatus> {
Poll::Ready(WriteStatus::Terminate)
}
#[inline]
fn get_read_buf(&self) -> Option<BytesVec> {
None
}
#[inline]
fn get_write_buf(&self) -> Option<BytesVec> {
None
}
#[inline]
fn release_read_buf(&self, _: BytesVec) {}
#[inline]
fn process_read_buf(&self, _: &IoRef, _: usize) -> io::Result<(usize, usize)> {
Ok((0, 0))
}
#[inline]
fn release_write_buf(&self, _: BytesVec) -> Result<(), io::Error> {
Ok(())
}

View file

@ -335,6 +335,7 @@ mod tests {
}
#[ntex::test]
#[allow(clippy::unit_cmp)]
async fn on_disconnect() {
let (client, server) = IoTest::create();
let state = Io::new(server);

View file

@ -82,3 +82,91 @@ where
req.add_filter(self.filter.clone())
}
}
#[cfg(test)]
mod tests {
use ntex_bytes::{Bytes, BytesVec};
use ntex_codec::BytesCodec;
use super::*;
use crate::{filter::NullFilter, testing::IoTest};
#[ntex::test]
async fn test_utils() {
let (client, server) = IoTest::create();
client.remote_buffer_cap(1024);
client.write("REQ");
let svc = seal(fn_service(|io: IoBoxed| async move {
let t = io.recv(&BytesCodec).await.unwrap().unwrap();
assert_eq!(t, b"REQ".as_ref());
io.send(Bytes::from_static(b"RES"), &BytesCodec)
.await
.unwrap();
Ok::<_, ()>(())
}))
.create(())
.await
.unwrap();
let _ = svc.call(Io::new(server)).await;
let buf = client.read().await.unwrap();
assert_eq!(buf, b"RES".as_ref());
}
#[derive(Copy, Clone, Debug)]
struct NullFilterFactory;
impl<F: Filter> FilterFactory<F> for NullFilterFactory {
type Filter = crate::filter::NullFilter;
type Error = std::convert::Infallible;
type Future = Ready<Io<Self::Filter>, Self::Error>;
fn create(self, st: Io<F>) -> Self::Future {
st.map_filter(|_| Ok(NullFilter)).into()
}
}
#[ntex::test]
async fn test_utils_filter() {
let (_, server) = IoTest::create();
let svc = pipeline_factory(
filter::<_, crate::filter::Base>(NullFilterFactory)
.map_err(|_| ())
.map_init_err(|_| ()),
)
.and_then(seal(fn_service(|io: IoBoxed| async move {
let _ = io.recv(&BytesCodec).await;
Ok::<_, ()>(())
})))
.create(())
.await
.unwrap();
let _ = svc.call(Io::new(server)).await;
}
#[ntex::test]
async fn test_null_filter() {
assert!(NullFilter.query(std::any::TypeId::of::<()>()).is_none());
assert!(NullFilter.poll_shutdown().is_ready());
assert_eq!(
ntex_util::future::poll_fn(|cx| NullFilter.poll_read_ready(cx)).await,
crate::ReadStatus::Terminate
);
assert_eq!(
ntex_util::future::poll_fn(|cx| NullFilter.poll_write_ready(cx)).await,
crate::WriteStatus::Terminate
);
assert_eq!(NullFilter.get_read_buf(), None);
assert_eq!(NullFilter.get_write_buf(), None);
assert!(NullFilter.release_write_buf(BytesVec::new()).is_ok());
NullFilter.release_read_buf(BytesVec::new());
let (_, server) = IoTest::create();
let io = Io::new(server);
assert_eq!(
NullFilter.process_read_buf(&io.get_ref(), 10).unwrap(),
(0, 0)
)
}
}

View file

@ -771,6 +771,7 @@ mod tests {
assert_eq!(tree.find(&mut Path::new("/2345/sdg")), Some(1));
assert_eq!(tree.find(&mut Path::new("/user/2345/sdg")), Some(1));
#[allow(clippy::needless_borrow)]
let re = ResourceDef::new(&("/user*".to_string()));
let tree = Tree::new(&re, 1);
assert_eq!(tree.find(&mut Path::new("/user/profile")), Some(1));
@ -956,31 +957,31 @@ mod tests {
fn test_resource_path() {
let mut s = String::new();
let resource = ResourceDef::new("/user/{item1}/test");
assert!(resource.resource_path(&mut s, &mut (&["user1"]).iter()));
assert!(resource.resource_path(&mut s, &mut ["user1"].iter()));
assert_eq!(s, "/user/user1/test");
let mut s = String::new();
let resource = ResourceDef::new("/user/{item1}/{item2}/test");
assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter()));
assert!(resource.resource_path(&mut s, &mut ["item", "item2"].iter()));
assert_eq!(s, "/user/item/item2/test");
let mut s = String::new();
let resource = ResourceDef::new("/user/{item1}/{item2}");
assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter()));
assert!(resource.resource_path(&mut s, &mut ["item", "item2"].iter()));
assert_eq!(s, "/user/item/item2");
let mut s = String::new();
let resource = ResourceDef::new("/user/{item1}/{item2}/");
assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter()));
assert!(resource.resource_path(&mut s, &mut ["item", "item2"].iter()));
assert_eq!(s, "/user/item/item2/");
let mut s = String::new();
assert!(!resource.resource_path(&mut s, &mut (&["item"]).iter()));
assert!(!resource.resource_path(&mut s, &mut ["item"].iter()));
let mut s = String::new();
assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter()));
assert!(resource.resource_path(&mut s, &mut ["item", "item2"].iter()));
assert_eq!(s, "/user/item/item2/");
assert!(!resource.resource_path(&mut s, &mut (&["item"]).iter()));
assert!(!resource.resource_path(&mut s, &mut ["item"].iter()));
let mut s = String::new();
assert!(resource.resource_path(&mut s, &mut vec!["item", "item2"].into_iter()));

View file

@ -69,15 +69,15 @@ mod glommio {
F: Future + 'static,
F::Output: 'static,
{
let ptr = crate::CB.with(|cb| (&cb.borrow().0)());
let ptr = crate::CB.with(|cb| (cb.borrow().0)());
JoinHandle {
fut: Either::Left(
glomm_io::spawn_local(async move {
if let Some(ptr) = ptr {
let new_ptr = crate::CB.with(|cb| (&cb.borrow().1)(ptr));
let new_ptr = crate::CB.with(|cb| (cb.borrow().1)(ptr));
glomm_io::executor().yield_now().await;
let res = f.await;
crate::CB.with(|cb| (&cb.borrow().2)(new_ptr));
crate::CB.with(|cb| (cb.borrow().2)(new_ptr));
res
} else {
glomm_io::executor().yield_now().await;
@ -170,12 +170,12 @@ mod tokio {
where
F: Future + 'static,
{
let ptr = crate::CB.with(|cb| (&cb.borrow().0)());
let ptr = crate::CB.with(|cb| (cb.borrow().0)());
tok_io::task::spawn_local(async move {
if let Some(ptr) = ptr {
let new_ptr = crate::CB.with(|cb| (&cb.borrow().1)(ptr));
let new_ptr = crate::CB.with(|cb| (cb.borrow().1)(ptr));
let res = f.await;
crate::CB.with(|cb| (&cb.borrow().2)(new_ptr));
crate::CB.with(|cb| (cb.borrow().2)(new_ptr));
res
} else {
f.await
@ -224,13 +224,13 @@ mod asyncstd {
where
F: Future + 'static,
{
let ptr = crate::CB.with(|cb| (&cb.borrow().0)());
let ptr = crate::CB.with(|cb| (cb.borrow().0)());
JoinHandle {
fut: async_std::task::spawn_local(async move {
if let Some(ptr) = ptr {
let new_ptr = crate::CB.with(|cb| (&cb.borrow().1)(ptr));
let new_ptr = crate::CB.with(|cb| (cb.borrow().1)(ptr));
let res = f.await;
crate::CB.with(|cb| (&cb.borrow().2)(new_ptr));
crate::CB.with(|cb| (cb.borrow().2)(new_ptr));
res
} else {
f.await

View file

@ -125,18 +125,19 @@ mod test {
use super::*;
#[test]
#[allow(clippy::unit_cmp)]
fn either() {
let mut e = Either::<(), ()>::Left(());
assert_eq!(e.is_left(), true);
assert_eq!(e.is_right(), false);
assert!(e.is_left());
assert!(!e.is_right());
assert!(e.left().is_some());
assert!(e.right().is_none());
e.as_ref();
e.as_mut();
let e = Either::<(), ()>::Right(());
assert_eq!(e.is_left(), false);
assert_eq!(e.is_right(), true);
assert!(!e.is_left());
assert!(e.is_right());
assert!(e.left().is_none());
assert!(e.right().is_some());

View file

@ -302,6 +302,7 @@ mod tests {
}
#[ntex_macros::rt_test2]
#[allow(clippy::redundant_clone)]
async fn test_newtransform() {
let inner = Rc::new(Inner {
ready: Cell::new(false),

View file

@ -124,7 +124,7 @@ mod tests {
fn call(&self, _: ()) -> Self::Future<'_> {
let fut = crate::time::sleep(self.0);
Box::pin(async move {
let _ = fut.await;
fut.await;
Ok::<_, ()>(())
})
}

View file

@ -241,7 +241,7 @@ mod tests {
fn call(&self, _: ()) -> Self::Future<'_> {
let fut = crate::time::sleep(self.0);
Box::pin(async move {
let _ = fut.await;
fut.await;
Ok::<_, SrvError>(())
})
}

View file

@ -352,7 +352,7 @@ mod tests {
.clone()
.v3(fn_factory(|| async { Ok::<_, ()>(Srv2) }))
.clone();
let service = factory.create(&()).await.unwrap();
let service = factory.create(&()).await.unwrap().clone();
assert!(lazy(|cx| service.poll_ready(cx)).await.is_ready());
assert!(lazy(|cx| service.poll_shutdown(cx)).await.is_ready());

View file

@ -426,14 +426,10 @@ mod tests {
fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool {
match err {
JsonPayloadError::Payload(PayloadError::Overflow) => match other {
JsonPayloadError::Payload(PayloadError::Overflow) => true,
_ => false,
},
JsonPayloadError::ContentType => match other {
JsonPayloadError::ContentType => true,
_ => false,
},
JsonPayloadError::Payload(PayloadError::Overflow) => {
matches!(other, JsonPayloadError::Payload(PayloadError::Overflow))
}
JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType),
_ => false,
}
}

View file

@ -752,10 +752,7 @@ mod tests {
}
fn is_unhandled(&self) -> bool {
match self {
PayloadType::Stream(_) => true,
_ => false,
}
matches!(self, PayloadType::Stream(_))
}
}
@ -767,10 +764,7 @@ mod tests {
}
}
fn eof(&self) -> bool {
match *self {
PayloadItem::Eof => true,
_ => false,
}
matches!(*self, PayloadItem::Eof)
}
}

View file

@ -953,7 +953,7 @@ mod tests {
spawn_h1(server, |mut req: Request| async move {
let mut p = req.take_payload();
while let Some(_) = stream_recv(&mut p).await {}
while (stream_recv(&mut p).await).is_some() {}
Ok::<_, io::Error>(Response::Ok().finish())
});

View file

@ -775,10 +775,8 @@ mod tests {
.route(
"/test",
web::get().to(|req: HttpRequest| async move {
HttpResponse::Ok().body(format!(
"{}",
req.url_for("youtube", &["12345"]).unwrap()
))
HttpResponse::Ok()
.body(format!("{}", req.url_for("youtube", ["12345"]).unwrap()))
}),
),
)

View file

@ -164,10 +164,8 @@ mod tests {
.route(
"/test",
web::get().to(|req: HttpRequest| async move {
HttpResponse::Ok().body(format!(
"{}",
req.url_for("youtube", &["12345"]).unwrap()
))
HttpResponse::Ok()
.body(format!("{}", req.url_for("youtube", ["12345"]).unwrap()))
}),
),
)

View file

@ -408,14 +408,14 @@ mod tests {
.to_http_request();
assert_eq!(
req.url_for("unknown", &["test"]),
req.url_for("unknown", ["test"]),
Err(crate::web::error::UrlGenerationError::ResourceNotFound)
);
assert_eq!(
req.url_for("index", &["test"]),
req.url_for("index", ["test"]),
Err(crate::web::error::UrlGenerationError::NotEnoughElements)
);
let url = req.url_for("index", &["test", "html"]);
let url = req.url_for("index", ["test", "html"]);
assert_eq!(
url.ok().unwrap().as_str(),
"http://www.rust-lang.org/user/test.html"
@ -456,7 +456,7 @@ mod tests {
// assert!(rmap.has_resource("https://youtube.com/watch/unknown"));
let req = TestRequest::default().rmap(rmap).to_http_request();
let url = req.url_for("youtube", &["oHg5SJYRHA0"]);
let url = req.url_for("youtube", ["oHg5SJYRHA0"]);
assert_eq!(
url.ok().unwrap().as_str(),
"https://youtube.com/watch/oHg5SJYRHA0"

View file

@ -1239,7 +1239,7 @@ mod tests {
"/",
web::get().to(|req: HttpRequest| async move {
HttpResponse::Ok().body(
req.url_for("youtube", &["xxxxxx"])
req.url_for("youtube", ["xxxxxx"])
.unwrap()
.as_str()
.to_string(),
@ -1264,7 +1264,7 @@ mod tests {
web::scope("/b").service(web::resource("/c/{stuff}").name("c").route(
web::get().to(|req: HttpRequest| async move {
HttpResponse::Ok()
.body(format!("{}", req.url_for("c", &["12345"]).unwrap()))
.body(format!("{}", req.url_for("c", ["12345"]).unwrap()))
}),
)),
)))

View file

@ -942,7 +942,7 @@ mod tests {
.origin("test-origin")
.max_frame_size(100)
.server_mode()
.protocols(&["v1", "v2"])
.protocols(["v1", "v2"])
.set_header_if_none(header::CONTENT_TYPE, "json")
.set_header_if_none(header::CONTENT_TYPE, "text")
.cookie(Cookie::build("cookie1", "value1").finish())
@ -952,7 +952,7 @@ mod tests {
"test-origin"
);
assert_eq!(builder.inner.as_ref().unwrap().max_size, 100);
assert_eq!(builder.inner.as_ref().unwrap().server_mode, true);
assert!(builder.inner.as_ref().unwrap().server_mode);
assert_eq!(builder.protocols, Some("v1,v2".to_string()));
let client = builder.finish().unwrap();

View file

@ -228,10 +228,7 @@ mod tests {
}
fn is_none(frm: &Result<Option<(bool, OpCode, Option<Bytes>)>, ProtocolError>) -> bool {
match *frm {
Ok(None) => true,
_ => false,
}
matches!(*frm, Ok(None))
}
fn extract(frm: Result<Option<(bool, OpCode, Option<Bytes>)>, ProtocolError>) -> F {
@ -315,7 +312,7 @@ mod tests {
#[test]
fn test_parse_frame_no_mask() {
let mut buf = BytesMut::from(&[0b0000_0001u8, 0b0000_0001u8][..]);
buf.extend(&[1u8]);
buf.extend([1u8]);
assert!(Parser::parse(&mut buf, true, 1024).is_err());
@ -328,7 +325,7 @@ mod tests {
#[test]
fn test_parse_frame_max_size() {
let mut buf = BytesMut::from(&[0b0000_0001u8, 0b0000_0010u8][..]);
buf.extend(&[1u8, 1u8]);
buf.extend([1u8, 1u8]);
assert!(Parser::parse(&mut buf, true, 1).is_err());

View file

@ -773,14 +773,12 @@ async fn test_client_cookie_handling() {
})
.map_err(|_| Error::new(IoError::from(ErrorKind::NotFound)));
if let Err(e) = res {
Err(e)
} else {
// Send some cookies back
Ok::<_, Error>(
HttpResponse::Ok().cookie(cookie1).cookie(cookie2).finish(),
)
}
res?;
// Send some cookies back
Ok::<_, Error>(
HttpResponse::Ok().cookie(cookie1).cookie(cookie2).finish(),
)
}
})),
)

View file

@ -499,14 +499,10 @@ async fn test_ws_transport() {
.await?;
// start websocket service
loop {
if let Some(item) =
io.recv(&BytesCodec).await.map_err(|e| e.into_inner())?
{
io.send(item.freeze(), &BytesCodec).await.unwrap()
} else {
break;
}
while let Some(item) =
io.recv(&BytesCodec).await.map_err(|e| e.into_inner())?
{
io.send(item.freeze(), &BytesCodec).await.unwrap()
}
Ok::<_, io::Error>(())
}

View file

@ -337,17 +337,17 @@ async fn test_content_length() {
{
for i in 0..4 {
let req = srv.request(Method::GET, &format!("/{}", i));
let req = srv.request(Method::GET, format!("/{}", i));
let response = req.send().await.unwrap();
assert_eq!(response.headers().get(&header), None);
let req = srv.request(Method::HEAD, &format!("/{}", i));
let req = srv.request(Method::HEAD, format!("/{}", i));
let response = req.send().await.unwrap();
assert_eq!(response.headers().get(&header), None);
}
for i in 4..6 {
let req = srv.request(Method::GET, &format!("/{}", i));
let req = srv.request(Method::GET, format!("/{}", i));
let response = req.send().await.unwrap();
assert_eq!(response.headers().get(&header), Some(&value));
}

View file

@ -259,14 +259,10 @@ async fn test_transport() {
.await?;
// start websocket service
loop {
if let Some(item) =
io.recv(&BytesCodec).await.map_err(|e| e.into_inner())?
{
io.send(item.freeze(), &BytesCodec).await.unwrap()
} else {
break;
}
while let Some(item) =
io.recv(&BytesCodec).await.map_err(|e| e.into_inner())?
{
io.send(item.freeze(), &BytesCodec).await.unwrap()
}
Ok::<_, io::Error>(())
}