()
| 147 | |
| 148 | #[tokio::test] |
| 149 | async fn no_cache_mode() -> Result<()> { |
| 150 | let mock_server = MockServer::start().await; |
| 151 | let m = build_mock(CACHEABLE_PUBLIC, TEST_BODY, 200, 2); |
| 152 | let _mock_guard = mock_server.register_as_scoped(m).await; |
| 153 | let url = format!("{}/", mock_server.uri()); |
| 154 | let manager = QuickManager::default(); |
| 155 | |
| 156 | // Construct reqwest client with cache defaults |
| 157 | let client = ClientBuilder::new(Client::new()) |
| 158 | .with(Cache(HttpCache { |
| 159 | mode: CacheMode::NoCache, |
| 160 | manager: manager.clone(), |
| 161 | options: HttpCacheOptions::default(), |
| 162 | })) |
| 163 | .build(); |
| 164 | |
| 165 | // Remote request and should cache |
| 166 | client.get(url.clone()).send().await?; |
| 167 | |
| 168 | // Try to load cached object |
| 169 | let data = http_cache::CacheManager::get( |
| 170 | &manager, |
| 171 | &format!("{}:{}", GET, url_parse(&url)?), |
| 172 | ) |
| 173 | .await?; |
| 174 | assert!(data.is_some()); |
| 175 | |
| 176 | // To verify our endpoint receives the request rather than a cache hit |
| 177 | client.get(url).send().await?; |
| 178 | Ok(()) |
| 179 | } |
| 180 | |
| 181 | #[tokio::test] |
| 182 | async fn head_request_caching() -> Result<()> { |
nothing calls this directly
no test coverage detected