| 34 | |
| 35 | #[apply(test!)] |
| 36 | async fn quickcache() -> Result<()> { |
| 37 | // Added to test custom Debug impl |
| 38 | assert_eq!( |
| 39 | format!("{:?}", QuickManager::default()), |
| 40 | "QuickManager { cache: \"Cache<String, Arc<Vec<u8>>>\", .. }", |
| 41 | ); |
| 42 | let url = url_parse("http://example.com")?; |
| 43 | let manager = Arc::new(QuickManager::default()); |
| 44 | let http_res = HttpResponse { |
| 45 | body: TEST_BODY.to_vec(), |
| 46 | headers: Default::default(), |
| 47 | status: 200, |
| 48 | url: url.clone(), |
| 49 | version: HttpVersion::Http11, |
| 50 | metadata: None, |
| 51 | }; |
| 52 | let req = http::Request::get("http://example.com").body(())?; |
| 53 | let res = http::Response::builder().status(200).body(TEST_BODY.to_vec())?; |
| 54 | let policy = CachePolicy::new(&req, &res); |
| 55 | CacheManager::put( |
| 56 | &*manager, |
| 57 | format!("{}:{}", GET, url), |
| 58 | http_res.clone(), |
| 59 | policy.clone(), |
| 60 | ) |
| 61 | .await?; |
| 62 | let data = |
| 63 | CacheManager::get(&*manager, &format!("{}:{}", GET, url)).await?; |
| 64 | assert!(data.is_some()); |
| 65 | assert_eq!(data.unwrap().0.body, TEST_BODY); |
| 66 | CacheManager::delete(&*manager, &format!("{}:{}", GET, url)).await?; |
| 67 | let data = |
| 68 | CacheManager::get(&*manager, &format!("{}:{}", GET, url)).await?; |
| 69 | assert!(data.is_none()); |
| 70 | Ok(()) |
| 71 | } |
| 72 | |
| 73 | #[tokio::test] |
| 74 | async fn default_mode() -> Result<()> { |