Refactored test.
This commit is contained in:
parent
572abbeda8
commit
da26693242
@ -274,17 +274,25 @@ mod caches {
|
|||||||
s
|
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_std::test]
|
||||||
async fn create() {
|
async fn create() {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let s_cache = start_cache(dir.path()).await;
|
let s_cache = start_cache(dir.path()).await;
|
||||||
let (s_rep, r_rep) = unbounded();
|
let result = send_request(vec![ENTRY], s_cache).await;
|
||||||
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();
|
|
||||||
match result {
|
match result {
|
||||||
FromCache::Data(data) => match data.get(ENTRY) {
|
FromCache::Data(data) => match data.get(ENTRY) {
|
||||||
Some(output) => match output {
|
Some(output) => match output {
|
||||||
@ -301,13 +309,7 @@ mod caches {
|
|||||||
async fn bad_entry() {
|
async fn bad_entry() {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let s_cache = start_cache(dir.path()).await;
|
let s_cache = start_cache(dir.path()).await;
|
||||||
let (s_rep, r_rep) = unbounded();
|
let result = send_request(vec!["bad_id"], s_cache).await;
|
||||||
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();
|
|
||||||
match result {
|
match result {
|
||||||
FromCache::Error(_) => (),
|
FromCache::Error(_) => (),
|
||||||
_ => assert!(false, "{:?} should have been an error.", result),
|
_ => assert!(false, "{:?} should have been an error.", result),
|
||||||
|
Loading…
Reference in New Issue
Block a user