test(cache): add tests for cache module

This commit is contained in:
Orhun Parmaksız 2021-12-04 23:25:24 +03:00
parent cf151b4108
commit 41ca625e99
No known key found for this signature in database
GPG key ID: F83424824B3E4B90

View file

@ -81,3 +81,23 @@ impl Cache {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::env;
#[test]
fn test_cache() -> Result<()> {
let cache = Cache::init()?;
let data = String::from("cache_test");
let cache_data = CacheData::new(
&data,
&Path::new(env!("CARGO_MANIFEST_DIR")).join("Cargo.toml"),
)?;
cache.write(cache_data, "data")?;
assert!(cache.exists("data"));
assert_eq!(data, cache.read::<String>("data")?.data);
Ok(())
}
}