1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00
actix-extras/tests/test_redis.rs

64 lines
1.9 KiB
Rust
Raw Normal View History

2018-01-23 07:28:29 +01:00
#[macro_use]
extern crate redis_async;
use actix::prelude::*;
2018-05-08 19:12:57 +02:00
use actix_redis::{Command, Error, RedisActor, RespValue};
2018-01-23 07:28:29 +01:00
use futures::Future;
#[test]
2019-03-29 19:31:48 +01:00
fn test_error_connect() -> std::io::Result<()> {
2018-01-23 07:28:29 +01:00
let sys = System::new("test");
let addr = RedisActor::start("localhost:54000");
let _addr2 = addr.clone();
2018-07-20 23:53:56 +02:00
Arbiter::spawn_fn(move || {
addr.send(Command(resp_array!["GET", "test"])).then(|res| {
match res {
Ok(Err(Error::NotConnected)) => (),
_ => panic!("Should not happen {:?}", res),
}
System::current().stop();
Ok(())
})
2018-01-23 07:28:29 +01:00
});
2019-03-29 19:31:48 +01:00
sys.run()
2018-01-23 07:28:29 +01:00
}
#[test]
2019-03-29 19:31:48 +01:00
fn test_redis() -> std::io::Result<()> {
2018-01-23 07:28:29 +01:00
env_logger::init();
let sys = System::new("test");
let addr = RedisActor::start("127.0.0.1:6379");
let _addr2 = addr.clone();
2018-07-20 23:53:56 +02:00
Arbiter::spawn_fn(move || {
2018-01-23 07:28:29 +01:00
let addr2 = addr.clone();
2018-02-16 01:53:05 +01:00
addr.send(Command(resp_array!["SET", "test", "value"]))
2018-01-23 07:28:29 +01:00
.then(move |res| match res {
Ok(Ok(resp)) => {
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
2018-07-20 23:53:56 +02:00
addr2.send(Command(resp_array!["GET", "test"])).then(|res| {
match res {
Ok(Ok(resp)) => {
println!("RESP: {:?}", resp);
assert_eq!(
resp,
RespValue::BulkString((&b"value"[..]).into())
);
2018-01-23 07:28:29 +01:00
}
2018-07-20 23:53:56 +02:00
_ => panic!("Should not happen {:?}", res),
}
System::current().stop();
Ok(())
})
2018-05-08 19:12:57 +02:00
}
2018-01-23 07:28:29 +01:00
_ => panic!("Should not happen {:?}", res),
})
});
2019-03-29 19:31:48 +01:00
sys.run()
2018-01-23 07:28:29 +01:00
}