1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 23:51:06 +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;
use actix_redis::{Command, Error, RedisActor, RespValue};
2018-01-23 07:28:29 +01:00
2022-02-03 23:33:47 +01:00
#[actix_web::test]
2019-12-15 18:46:03 +01:00
async fn test_error_connect() {
let addr = RedisActor::start("localhost:54000");
let _addr2 = addr.clone();
2018-01-23 07:28:29 +01:00
let res = addr.send(Command(resp_array!["GET", "test"])).await;
2019-12-15 18:46:03 +01:00
match res {
Ok(Err(Error::NotConnected)) => (),
2019-12-15 18:46:03 +01:00
_ => panic!("Should not happen {:?}", res),
}
2018-01-23 07:28:29 +01:00
}
2022-02-03 23:33:47 +01:00
#[actix_web::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");
let res = addr
.send(Command(resp_array!["SET", "test", "value"]))
.await;
2019-12-15 18:46:03 +01:00
match res {
Ok(Ok(resp)) => {
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
let res = addr.send(Command(resp_array!["GET", "test"])).await;
match res {
Ok(Ok(resp)) => {
2023-01-07 02:04:16 +01:00
println!("RESP: {resp:?}");
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
}
_ => panic!("Should not happen {:?}", res),
}
}
_ => panic!("Should not happen {:?}", res),
}
2018-01-23 07:28:29 +01:00
}