implement client ping (#108)

This commit is contained in:
Kim Chan
2022-08-25 17:10:32 +08:00
committed by GitHub
parent d3826795af
commit c1c3bcb465
4 changed files with 84 additions and 1 deletions

View File

@@ -3,6 +3,28 @@ use std::net::SocketAddr;
use tokio::net::TcpListener;
use tokio::task::JoinHandle;
/// A PING PONG test without message provided.
/// It should return "PONG".
#[tokio::test]
async fn ping_pong_without_message() {
let (addr, _) = start_server().await;
let mut client = client::connect(addr).await.unwrap();
let pong = client.ping(None).await.unwrap();
assert_eq!(b"PONG", &pong[..]);
}
/// A PING PONG test with message provided.
/// It should return the message.
#[tokio::test]
async fn ping_pong_with_message() {
let (addr, _) = start_server().await;
let mut client = client::connect(addr).await.unwrap();
let pong = client.ping(Some("你好世界".to_string())).await.unwrap();
assert_eq!("你好世界".as_bytes(), &pong[..]);
}
/// A basic "hello world" style test. A server instance is started in a
/// background task. A client instance is then established and set and get
/// commands are sent to the server. The response is then evaluated