MCPcopy Create free account
hub / github.com/06chaynes/http-cache / test_http_cache_interface_not_modified

Function test_http_cache_interface_not_modified

http-cache/src/test.rs:758–797  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

756 manager
757 .put(format!("{}:{}", GET, url), http_res.clone(), policy.clone())
758 .await?;
759 let data = manager.get(&format!("{}:{}", GET, url)).await?;
760 assert!(data.is_some());
761 let response = data.unwrap();
762 assert_eq!(response.0.body, TEST_BODY);
763 assert_eq!(response.0.metadata, Some(b"Metadata".to_vec()));
764 let clone = manager.clone();
765 let clonedata = clone.get(&format!("{}:{}", GET, url)).await?;
766 assert!(clonedata.is_some());
767 let response = clonedata.unwrap();
768 assert_eq!(response.0.body, TEST_BODY);
769 assert_eq!(response.0.metadata, Some(b"Metadata".to_vec()));
770 manager.delete(&format!("{}:{}", GET, url)).await?;
771 let data = manager.get(&format!("{}:{}", GET, url)).await?;
772 assert!(data.is_none());
773
774 // Note: FoyerManager doesn't have a clear() method like cacache/moka
775 // since foyer handles eviction internally
776 Ok(())
777 }
778
779 #[tokio::test]
780 async fn foyer_corrupt_data_returns_none() -> Result<()> {
781 // Build the cache directly so we can insert corrupt data
782 let cache: foyer::HybridCache<String, Vec<u8>> =
783 foyer::HybridCacheBuilder::new()
784 .memory(100)
785 .storage()
786 .build()
787 .await
788 .unwrap();
789 let key = "GET:http://example.com/corrupt";
790
791 // Write corrupt data directly to the cache
792 cache.insert(key.to_string(), b"not valid serialized data".to_vec());
793
794 // Wrap in FoyerManager
795 let manager = FoyerManager::new(cache);
796
797 // get() should return Ok(None) instead of an error
798 let result = manager.get(key).await?;
799 assert!(result.is_none());
800 Ok(())

Callers

nothing calls this directly

Calls 6

url_parseFunction · 0.85
bodyMethod · 0.80
headerMethod · 0.80
statusMethod · 0.80
handle_not_modifiedMethod · 0.80
cloneMethod · 0.80

Tested by

no test coverage detected