cachier/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mod cachier;

#[cfg(test)]
mod tests {
    use serde_json::json;
    use super::*;

    #[tokio::test]
    async fn test_set_and_get() {
        let cache = cachier::Cachier::new("https://example.com/api".to_string(), "memory".to_string());

        // Test that the `set` method returns true when the value is stored successfully
        let is_saved = cache.set("key", json!("value"), Some(3600)).await;
        assert!(is_saved);

        // Test that the `get` method returns the correct value when the key is found in the cache
        let result = cache.get(Some("key")).await.unwrap();
        assert_eq!(result, "value");

        // Test that the `get` method returns "none" when the key is not found in the cache
        let result = cache.get(Some("invalid_key")).await.unwrap();
        assert_eq!(result, "none");
    }
}