use std::str::FromStr;
use crate::{resp::cmd, tests::get_test_client, Error, RedisError, RedisErrorKind, Result};
use serial_test::serial;
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn unknown_command() -> Result<()> {
let mut client = get_test_client().await?;
let result = client.send(cmd("UNKNOWN").arg("arg")).await;
assert!(matches!(
result,
Err(Error::Redis(RedisError {
kind: RedisErrorKind::Err,
description
})) if description.starts_with("unknown command 'UNKNOWN'")
));
Ok(())
}
#[test]
fn moved_error() {
let raw_error = "MOVED 3999 127.0.0.1:6381";
let error = RedisError::from_str(raw_error);
println!("error: {error:?}");
assert!(matches!(
error,
Ok(RedisError {
kind: RedisErrorKind::Moved { hash_slot: 3999, address: (host, 6381) },
description
}) if description.is_empty() && host == "127.0.0.1"
));
}
#[test]
fn ask_error() {
let raw_error = "ASK 3999 127.0.0.1:6381";
let error = RedisError::from_str(raw_error);
assert!(matches!(
error,
Ok(RedisError {
kind: RedisErrorKind::Ask { hash_slot: 3999, address: (host, 6381) },
description
}) if description.is_empty() && host == "127.0.0.1"
));
}