1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-12-18 09:43:11 +01:00
actix-extras/actix-redis/tests/test_redis.rs

43 lines
1.2 KiB
Rust
Raw Normal View History

2018-01-23 07:28:29 +01:00
#[macro_use]
extern crate redis_async;
2018-05-08 19:12:57 +02:00
use actix_redis::{Command, Error, RedisActor, RespValue};
2018-01-23 07:28:29 +01:00
2019-12-15 18:46:03 +01:00
#[actix_rt::test]
async fn test_error_connect() {
2018-01-23 07:28:29 +01:00
let addr = RedisActor::start("localhost:54000");
let _addr2 = addr.clone();
2019-12-15 18:46:03 +01:00
let res = addr.send(Command(resp_array!["GET", "test"])).await;
match res {
Ok(Err(Error::NotConnected)) => (),
_ => panic!("Should not happen {:?}", res),
}
2018-01-23 07:28:29 +01:00
}
2019-12-15 18:46:03 +01:00
#[actix_rt::test]
async fn test_redis() {
2018-01-23 07:28:29 +01:00
env_logger::init();
let addr = RedisActor::start("127.0.0.1:6379");
2019-12-15 18:46:03 +01:00
let res = addr
.send(Command(resp_array!["SET", "test", "value"]))
.await;
match res {
Ok(Ok(resp)) => {
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
2018-01-23 07:28:29 +01:00
2019-12-15 18:46:03 +01:00
let res = addr.send(Command(resp_array!["GET", "test"])).await;
match res {
2018-01-23 07:28:29 +01:00
Ok(Ok(resp)) => {
2019-12-15 18:46:03 +01:00
println!("RESP: {:?}", resp);
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
2018-05-08 19:12:57 +02:00
}
2018-01-23 07:28:29 +01:00
_ => panic!("Should not happen {:?}", res),
2019-12-15 18:46:03 +01:00
}
}
_ => panic!("Should not happen {:?}", res),
}
2018-01-23 07:28:29 +01:00
}