cache insertion and consumation tested

redo-gragh
Avril 4 years ago
parent de0c83f8b0
commit 4571fba664
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -10,6 +10,9 @@ use tokio::sync::{
use std::fs::Metadata;
/// A raw file or directory inode number
///
/// Ususally created from the `.inode()` extension method on `fs::Metadata` found in prelude.
/// Can also be created with `new()` from a `fs::Metadata` reference, or created unsafely from an arbitrary `u64` with `new_unchecked`.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
#[repr(transparent)]
pub struct INode(u64);
@ -36,6 +39,22 @@ impl INode
}
}
impl<'a> From<&'a Metadata> for INode
{
#[inline] fn from(from: &'a Metadata) -> Self
{
from.inode()
}
}
impl From<INode> for u64
{
#[inline] fn from(from: INode) -> Self
{
from.0
}
}
/// A valid file system info
///
/// # Note
@ -146,3 +165,24 @@ impl Cache
}
}
}
#[cfg(test)]
mod tests
{
use super::*;
#[tokio::test]
async fn cache_insert_and_consume()
{
let mut cache = Cache::new();
for x in 0..500
{
cache.insert(unsafe { INode::new_unchecked(x) }, FsInfo::Directory).await;
}
let output = cache.try_complete().await.unwrap();
assert_eq!(output.len(), 500);
for x in 0..500
{
assert_eq!(output.get(&unsafe { INode::new_unchecked(x) }).unwrap(), &FsInfo::Directory);
}
}
}

Loading…
Cancel
Save