use crate::commandstream::CommandStream;
use crate::errors::ClientError;
use crate::stream::Stream;
#[derive(Debug)]
pub struct Client {
pub(crate) port: u16,
pub(crate) host: String,
pub(crate) command_client: CommandStream,
}
impl Client {
pub fn new(host: String, port: u16) -> Result<Self, ClientError> {
let mut command_client = CommandStream::new(host.clone(), port)?;
command_client.handshake()?;
Ok(Client {
command_client,
host,
port,
})
}
}
#[cfg(test)]
mod tests {
use crate::watchstream::WatchStream;
use super::*;
const HOST: &str = "localhost";
const PORT: u16 = 7379;
#[test]
fn test_client() {
let d = Client::new(HOST.to_string(), PORT);
assert!(d.is_ok());
}
#[test]
fn test_client_error() {
let d = Client::new(HOST.to_string(), 0); assert!(d.is_err());
}
#[test]
fn test_client_error2() {
let wc = WatchStream::new(HOST.to_string(), 0); assert!(wc.is_err());
}
}