Skip to content

Commit

Permalink
add dummy constructor for MqttClient
Browse files Browse the repository at this point in the history
  • Loading branch information
GunnarMorrigan committed Jan 16, 2024
1 parent 40be420 commit dc29b86
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ rust-version = "1.75"
[features]
default = [
"smol",
"tokio",
"tokio"
]
sync = []
tokio = ["dep:tokio", "tokio/rt"]
smol = ["dep:smol"]
logs = ["dep:tracing"]
test = []

[dependencies]
# Packets
Expand Down
34 changes: 34 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ impl MqttClient {
max_packet_size,
}
}

/// This function is only here for you to use during testing of for example your handler
/// For a simple client look at [`MqttClient::dummy_client`]
#[cfg(feature = "test")]
pub fn dummy_custom_client(available_packet_ids_r: Receiver<u16>, to_network_s: Sender<Packet>, max_packet_size: usize) -> Self {
Self {
available_packet_ids_r,
to_network_s,
max_packet_size,
}
}

/// This function is only here for you to use during testing of for example your handler
/// For control over the input of this type look at [`MqttClient::dummy_custom_client`]
#[cfg(feature = "test")]
pub fn dummy_client() -> (Self, crate::available_packet_ids::AvailablePacketIds, Receiver<Packet>) {
use async_channel::unbounded;

use crate::{available_packet_ids::AvailablePacketIds, util::constants::MAXIMUM_PACKET_SIZE};

let (available_packet_ids, available_packet_ids_r) = AvailablePacketIds::new(u16::MAX);

let (s, r) = unbounded();

(
Self {
available_packet_ids_r,
to_network_s: s,
max_packet_size: MAXIMUM_PACKET_SIZE as usize,
},
available_packet_ids,
r
)
}
}

/// Async functions to perform MQTT operations
Expand Down

0 comments on commit dc29b86

Please sign in to comment.