Skip to content

Commit

Permalink
Add tests for OpenConnectionArguments getters.
Browse files Browse the repository at this point in the history
  • Loading branch information
eglimi committed Oct 13, 2024
1 parent 0c8ba7e commit e8c2118
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
38 changes: 37 additions & 1 deletion amqprs/src/api/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,8 @@ fn generate_connection_name(domain: &str) -> String {
#[cfg(test)]
mod tests {
use super::{generate_connection_name, Connection, OpenConnectionArguments};
use crate::security::SecurityCredentials;
use crate::test_utils::setup_logging;
use crate::{connection::AMQPS_SCHEME, security::SecurityCredentials};
use std::{collections::HashSet, thread};
use tokio::time;

Expand All @@ -1329,6 +1329,42 @@ mod tests {
time::sleep(time::Duration::from_millis(100)).await;
}

#[test]
fn test_connection_getters() {
let args = OpenConnectionArguments::new("localhost", 5672, "user", "bitnami");
assert_eq!(args.get_host(), "localhost");
assert_eq!(args.get_port(), 5672);
assert_eq!(args.get_virtual_host(), "/");
assert!(args.get_connection_name().is_none());
assert!(args.get_credentials() == &SecurityCredentials::new_plain("user", "bitnami"));
assert_eq!(args.get_heartbeat(), 60);
assert!(args.get_scheme().is_none());
#[cfg(feature = "tls")]
assert!(args.get_tls_adaptor().is_none());
}

#[test]
fn test_custom_connection_getters() {
let mut default_args = OpenConnectionArguments {
..Default::default()
};
let args = default_args
.host("localhost")
.port(1234)
.virtual_host("/vhost")
.connection_name("test")
.credentials(SecurityCredentials::new_plain("user", "bitnami"))
.heartbeat(30)
.scheme("amqps");
assert_eq!(args.get_host(), "localhost");
assert_eq!(args.get_port(), 1234);
assert_eq!(args.get_virtual_host(), "/vhost");
assert!(args.get_connection_name() == Some("test"));
assert!(args.get_credentials() == &SecurityCredentials::new_plain("user", "bitnami"));
assert_eq!(args.get_heartbeat(), 30);
assert!(args.get_scheme() == Some(AMQPS_SCHEME));
}

#[tokio::test(flavor = "multi_thread", worker_threads = 10)]
async fn test_multi_conn_open_close() {
setup_logging();
Expand Down
4 changes: 2 additions & 2 deletions amqprs/src/api/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use amqp_serde::{
use bytes::BytesMut;

/// Credentials used to open a connection.
#[derive(Clone)]
#[derive(Clone, PartialEq)]
pub struct SecurityCredentials {
username: String,
password: String,
mechanism: AuthenticationMechanism,
}

#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone)]
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
enum AuthenticationMechanism {
PLAIN,
Expand Down

0 comments on commit e8c2118

Please sign in to comment.