From 4571fba6643002ba2947ce88f8b574afed9709fa Mon Sep 17 00:00:00 2001 From: Avril Date: Sat, 6 Feb 2021 16:57:24 +0000 Subject: [PATCH] cache insertion and consumation tested --- src/data.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/data.rs b/src/data.rs index 88b4fd3..5c708bc 100644 --- a/src/data.rs +++ b/src/data.rs @@ -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 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); + } + } +}