cachier/
lib.rs

1mod cachier;
2
3#[cfg(test)]
4mod tests {
5    use serde_json::json;
6    use super::*;
7
8    #[tokio::test]
9    async fn test_set_and_get() {
10        let cache = cachier::Cachier::new("https://example.com/api".to_string(), "memory".to_string());
11
12        // Test that the `set` method returns true when the value is stored successfully
13        let is_saved = cache.set("key", json!("value"), Some(3600)).await;
14        assert!(is_saved);
15
16        // Test that the `get` method returns the correct value when the key is found in the cache
17        let result = cache.get(Some("key")).await.unwrap();
18        assert_eq!(result, "value");
19
20        // Test that the `get` method returns "none" when the key is not found in the cache
21        let result = cache.get(Some("invalid_key")).await.unwrap();
22        assert_eq!(result, "none");
23    }
24}