Improve tests coverage (#161)

* improve tests coverage
* update base64 crate
This commit is contained in:
Nikolay Kim 2023-01-14 20:34:53 +06:00 committed by GitHub
parent 9bf0908f41
commit fc7553b8bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 137 additions and 51 deletions

View file

@ -27,4 +27,4 @@ simdutf8 = { version = "0.1.4", optional = true }
[dev-dependencies]
serde_test = "1.0"
serde_json = "1.0"
ntex = { version = "0.6.0-alpha.0", features = ["tokio"] }
ntex = { version = "0.6.0", features = ["tokio"] }

View file

@ -541,6 +541,8 @@ impl Bytes {
/// let b = a.slice(2..5);
///
/// assert_eq!(&b[..], b"llo");
/// assert_eq!(&b[..=1], b"ll");
/// assert_eq!(&b[1..=1], b"l");
/// ```
///
/// # Panics
@ -4047,7 +4049,7 @@ fn abort() {
#[cfg(test)]
mod tests {
use std::convert::TryFrom;
use std::{collections::HashMap, convert::TryFrom};
use super::*;
@ -4087,28 +4089,33 @@ mod tests {
let mut b: Bytes = BytesMut::try_from(b).unwrap().freeze();
assert_eq!(b, LONG);
assert_eq!(Buf::remaining(&b), LONG.len());
assert_eq!(Buf::chunk(&b), LONG);
Buf::advance(&mut b, 10);
assert!(!(b > b));
assert_eq!(<Bytes as Buf>::remaining(&b), LONG.len());
assert_eq!(<Bytes as Buf>::chunk(&b), LONG);
<Bytes as Buf>::advance(&mut b, 10);
assert_eq!(Buf::chunk(&b), &LONG[10..]);
let mut h: HashMap<Bytes, usize> = HashMap::default();
h.insert(b.clone(), 1);
assert_eq!(h.get(&b), Some(&1));
let mut b = BytesMut::try_from(LONG).unwrap();
assert_eq!(b, LONG);
assert_eq!(Buf::remaining(&b), LONG.len());
assert_eq!(BufMut::remaining_mut(&b), 25);
assert_eq!(Buf::chunk(&b), LONG);
Buf::advance(&mut b, 10);
assert_eq!(Buf::chunk(&b), &LONG[10..]);
assert_eq!(<BytesMut as Buf>::remaining(&b), LONG.len());
assert_eq!(<BytesMut as BufMut>::remaining_mut(&b), 25);
assert_eq!(<BytesMut as Buf>::chunk(&b), LONG);
<BytesMut as Buf>::advance(&mut b, 10);
assert_eq!(<BytesMut as Buf>::chunk(&b), &LONG[10..]);
let mut b = BytesMut::with_capacity(12);
BufMut::put_i8(&mut b, 1);
<BytesMut as BufMut>::put_i8(&mut b, 1);
assert_eq!(b, b"\x01".as_ref());
BufMut::put_u8(&mut b, 2);
<BytesMut as BufMut>::put_u8(&mut b, 2);
assert_eq!(b, b"\x01\x02".as_ref());
BufMut::put_slice(&mut b, b"12345");
<BytesMut as BufMut>::put_slice(&mut b, b"12345");
assert_eq!(b, b"\x01\x0212345".as_ref());
BufMut::chunk_mut(&mut b).write_byte(0, b'1');
unsafe { BufMut::advance_mut(&mut b, 1) };
<BytesMut as BufMut>::chunk_mut(&mut b).write_byte(0, b'1');
unsafe { <BytesMut as BufMut>::advance_mut(&mut b, 1) };
assert_eq!(b, b"\x01\x02123451".as_ref());
}

View file

@ -1064,7 +1064,14 @@ async fn pool_usage() {
let p_ref = PoolId::P1.set_pool_size(10 * 1024);
let p1 = p_ref.pool();
let p2 = p_ref.pool();
let p2 = p_ref.pool().clone();
let p_ref2 = PoolRef::from(&p1);
assert_eq!(p_ref2.read_params_high(), 4096);
assert_eq!(p_ref2.write_params_high(), 4096);
p_ref2.id().set_spawn_fn(|f| {
let _ = ntex::rt::spawn(f);
});
assert_eq!(Poll::Ready(()), util::lazy(|cx| p1.poll_ready(cx)).await);