Refactored test.
This commit is contained in:
parent
572abbeda8
commit
da26693242
@ -274,17 +274,25 @@ mod caches {
|
||||
s
|
||||
}
|
||||
|
||||
async fn send_request(data: Vec<&str>, channel: Sender<ToCache>) -> 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),
|
||||
|
Loading…
Reference in New Issue
Block a user