Skip to content

Commit

Permalink
Expose server_uri with AsyncClient
Browse files Browse the repository at this point in the history
Signed-off-by: Heiko Ronsdorf <heiko.ronsdorf@atos.net>
  • Loading branch information
Feelemoon committed Apr 26, 2023
1 parent 058c4f8 commit c0de42d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,14 @@ impl AsyncClient {
pub fn client_id(&self) -> String {
self.inner.client_id.clone().into_string().unwrap()
}

/// Returns server URI used for connection
///
/// Server URI is returned as a rust String as set in a
/// CreateOptionsBuilder for symmetry
pub fn server_uri(&self) -> String {
self.inner.server_uri.clone().into_string().unwrap()
}
}

// The client is safe to send or share between threads.
Expand Down Expand Up @@ -1370,4 +1378,18 @@ mod tests {
let retrieved = client.unwrap().client_id();
assert_eq!(retrieved, c_id.to_string());
}

#[test]
fn test_get_server_uri() {
let server_uri = "tcp://localhost:1883";
let client = CreateOptionsBuilder::new()
.server_uri(server_uri)
.create_client();
assert!(
client.is_ok(),
"Error in creating async client with server_uri"
);
let retrieved = client.unwrap().server_uri();
assert_eq!(retrieved, server_uri.to_string());
}
}

0 comments on commit c0de42d

Please sign in to comment.