message: test: Add failed connection test
diff: @@ -402,8 +402,17 @@ impl ButtplugClient {
  #[cfg(test)]
  mod test {
  use super::ButtplugClient;
  - use crate::client::connector::ButtplugEmbeddedClientConnector;
  - use async_std::task;
  + use crate::{
  + client::{
  + connector::{ButtplugEmbeddedClientConnector,
  + ButtplugClientConnector,
  + ButtplugClientConnectorError},
  + internal::ButtplugClientMessageStateShared,
  + },
  + core::messages::ButtplugMessageUnion,
  + };
  + use async_trait::async_trait;
  + use async_std::{task, sync::{channel, Receiver}};
  use env_logger;
  async fn connect_test_client(client: &mut ButtplugClient) {
  @@ -415,6 +424,46 @@ mod test {
  assert!(client.connected());
  }
  + #[derive(Default)]
  + struct ButtplugFailingClientConnector {
  + }
  +
  + #[async_trait]
  + impl ButtplugClientConnector for ButtplugFailingClientConnector {
  + async fn connect(&mut self) -> Option<ButtplugClientConnectorError> {
  + Some(ButtplugClientConnectorError::new("Always fails"))
  + }
  +
  + fn disconnect(&mut self) -> Option<ButtplugClientConnectorError> {
  + Some(ButtplugClientConnectorError::new("Always fails"))
  + }
  +
  + async fn send(&mut self, msg: &ButtplugMessageUnion, state: &ButtplugClientMessageStateShared) {
  + }
  +
  + fn get_event_receiver(&mut self) -> Receiver<ButtplugMessageUnion> {
  + // This will panic if we've already taken the receiver.
  + let (send, recv) = channel(256);
  + recv
  + }
  + }
  +
  +
  + #[test]
  + fn test_failing_connection() {
  + task::block_on(async {
  + ButtplugClient::run("Test Client", |mut client| {
  + async move {
  + assert!(client
  + .connect(ButtplugFailingClientConnector::default())
  + .await
  + .is_some());
  + assert!(!client.connected());
  + }
  + }).await;
  + });
  + }
  +
  #[test]
  fn test_connect_status() {
  task::block_on(async {
  