collect all clients to one single folder (#119)
This commit is contained in:
33
tests/buffered_client.rs
Normal file
33
tests/buffered_client.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use mini_redis::{
|
||||
clients::{BufferedClient, Client},
|
||||
server,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
/// A basic "hello world" style test. A server instance is started in a
|
||||
/// background task. A client instance is then established and used to intialize
|
||||
/// the buffer. Set and get commands are sent to the server. The response is
|
||||
/// then evaluated.
|
||||
#[tokio::test]
|
||||
async fn pool_key_value_get_set() {
|
||||
let (addr, _) = start_server().await;
|
||||
|
||||
let client = Client::connect(addr).await.unwrap();
|
||||
let mut client = BufferedClient::buffer(client);
|
||||
|
||||
client.set("hello", "world".into()).await.unwrap();
|
||||
|
||||
let value = client.get("hello").await.unwrap().unwrap();
|
||||
assert_eq!(b"world", &value[..])
|
||||
}
|
||||
|
||||
async fn start_server() -> (SocketAddr, JoinHandle<()>) {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
|
||||
let handle = tokio::spawn(async move { server::run(listener, tokio::signal::ctrl_c()).await });
|
||||
|
||||
(addr, handle)
|
||||
}
|
||||
Reference in New Issue
Block a user