1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00
actix-extras/actix-redis/tests/test_redis.rs

32 lines
823 B
Rust
Raw Normal View History

2018-01-23 07:28:29 +01:00
#[macro_use]
extern crate redis_async;
2021-03-21 23:50:26 +01:00
use actix_redis::{Error, RedisClient, 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() {
2021-03-21 23:50:26 +01:00
let addr = RedisClient::new("localhost:54000");
2018-01-23 07:28:29 +01:00
2021-03-21 23:50:26 +01:00
let res = addr.send(resp_array!["GET", "test"]).await;
2019-12-15 18:46:03 +01:00
match res {
2021-03-21 23:50:26 +01:00
Err(Error::NotConnected) => (),
2019-12-15 18:46:03 +01:00
_ => panic!("Should not happen {:?}", res),
}
2018-01-23 07:28:29 +01:00
}
2019-12-15 18:46:03 +01:00
#[actix_rt::test]
2021-03-21 23:50:26 +01:00
async fn test_redis() -> Result<(), Error> {
2018-01-23 07:28:29 +01:00
env_logger::init();
2021-03-21 23:50:26 +01:00
let addr = RedisClient::new("127.0.0.1:6379");
2019-12-15 18:46:03 +01:00
2021-03-21 23:50:26 +01:00
let resp = addr.send(resp_array!["SET", "test", "value"]).await?;
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
let resp = addr.send(resp_array!["GET", "test"]).await?;
println!("RESP: {:?}", resp);
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
Ok(())
2018-01-23 07:28:29 +01:00
}