From da2669324284852547ce9c7cf2524e154ad19d6b Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sun, 9 Apr 2023 09:45:39 -0400 Subject: [PATCH] Refactored test. --- src/morethantext/mod.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index dbbde18..7b498c5 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -274,17 +274,25 @@ mod caches { s } + async fn send_request(data: Vec<&str>, channel: Sender) -> FromCache { + let mut ids = Vec::new(); + for id in data.iter() { + ids.push(id.to_string()); + } + let (s, r) = unbounded(); + let msg = ToCache::Query( CacheQuery { + ids: ids, + reply: s, + }); + channel.send(msg).await.unwrap(); + r.recv().await.unwrap() + } + #[async_std::test] async fn create() { let dir = tempdir().unwrap(); let s_cache = start_cache(dir.path()).await; - let (s_rep, r_rep) = unbounded(); - let request = ToCache::Query(CacheQuery { - ids: [ENTRY.to_string()].to_vec(), - reply: s_rep, - }); - s_cache.send(request).await.unwrap(); - let result = r_rep.recv().await.unwrap(); + let result = send_request(vec![ENTRY], s_cache).await; match result { FromCache::Data(data) => match data.get(ENTRY) { Some(output) => match output { @@ -301,13 +309,7 @@ mod caches { async fn bad_entry() { let dir = tempdir().unwrap(); let s_cache = start_cache(dir.path()).await; - let (s_rep, r_rep) = unbounded(); - let request = ToCache::Query(CacheQuery { - ids: ["bad_id".to_string()].to_vec(), - reply: s_rep, - }); - s_cache.send(request).await.unwrap(); - let result = r_rep.recv().await.unwrap(); + let result = send_request(vec!["bad_id"], s_cache).await; match result { FromCache::Error(_) => (), _ => assert!(false, "{:?} should have been an error.", result),