spetz commented on PR #1803:
URL: https://github.com/apache/iggy/pull/1803#issuecomment-2907661502
It looks like some of the previous tests for connection strings were removed
(maybe by a mistake, when restructuring to the monorepo). Here's how it looked
before:
```rust
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn connection_string_without_username_should_fail() {
let server_address = "localhost:1234";
let value =
format!("{CONNECTION_STRING_PREFIX}:secret@{server_address}");
let connection_string: Result<ConnectionString, IggyError> =
ConnectionString::new(&value);
assert!(connection_string.is_err());
}
#[test]
fn connection_string_without_password_should_fail() {
let server_address = "localhost:1234";
let value =
format!("{CONNECTION_STRING_PREFIX}user1@{server_address}");
let connection_string = ConnectionString::new(&value);
assert!(connection_string.is_err());
}
#[test]
fn connection_string_without_server_address_should_fail() {
let value = format!("{CONNECTION_STRING_PREFIX}user:secret");
let connection_string = ConnectionString::new(&value);
assert!(connection_string.is_err());
}
#[test]
fn connection_string_without_port_should_fail() {
let value =
format!("{CONNECTION_STRING_PREFIX}user:secret@localhost");
let connection_string = ConnectionString::new(&value);
assert!(connection_string.is_err());
}
#[test]
fn connection_string_without_options_should_be_parsed_correctly() {
let username = "user1";
let password = "secret";
let server_address = "localhost:1234";
let value =
format!("{CONNECTION_STRING_PREFIX}{username}:{password}@{server_address}");
let connection_string = ConnectionString::new(&value);
assert!(connection_string.is_ok());
let connection_string = connection_string.unwrap();
assert_eq!(connection_string.server_address, server_address);
assert_eq!(
connection_string.auto_login,
AutoLogin::Enabled(Credentials::UsernamePassword(
username.to_string(),
password.to_string()
))
);
assert!(!connection_string.options.tls_enabled);
assert!(connection_string.options.tls_domain.is_empty());
assert!(connection_string.options.tls_ca_file.is_none());
assert!(connection_string.options.reconnection.enabled);
assert!(connection_string.options.reconnection.max_retries.is_none());
assert_eq!(
connection_string.options.reconnection.interval,
IggyDuration::from_str("1s").unwrap()
);
assert!(!connection_string.options.nodelay);
}
#[test]
fn connection_string_with_options_should_be_parsed_correctly() {
let username = "user1";
let password = "secret";
let server_address = "localhost:1234";
let tls = true;
let tls_domain = "test.com";
let tls_ca_file = "ca.pem";
let reconnection_retries = 5;
let reconnection_interval = "5s";
let reestablish_after = "10s";
let heartbeat_interval = "3s";
let nodelay = true;
let value =
format!("{CONNECTION_STRING_PREFIX}{username}:{password}@{server_address}?tls={tls}&tls_domain={tls_domain}&tls_ca_file={tls_ca_file}&reconnection_retries={reconnection_retries}&reconnection_interval={reconnection_interval}&reestablish_after={reestablish_after}&heartbeat_interval={heartbeat_interval}&nodelay={nodelay}");
let connection_string = ConnectionString::new(&value);
assert!(connection_string.is_ok());
let connection_string = connection_string.unwrap();
assert_eq!(connection_string.server_address, server_address);
assert_eq!(
connection_string.auto_login,
AutoLogin::Enabled(Credentials::UsernamePassword(
username.to_string(),
password.to_string()
))
);
assert!(connection_string.options.tls_enabled);
assert_eq!(connection_string.options.tls_enabled, tls);
assert_eq!(connection_string.options.tls_domain, tls_domain);
assert_eq!(
connection_string.options.tls_ca_file,
Some(tls_ca_file.to_owned())
);
assert!(connection_string.options.reconnection.enabled);
assert_eq!(
connection_string.options.reconnection.max_retries,
Some(reconnection_retries)
);
assert_eq!(
connection_string.options.reconnection.interval,
IggyDuration::from_str(reconnection_interval).unwrap()
);
assert_eq!(
connection_string.options.reconnection.reestablish_after,
IggyDuration::from_str(reestablish_after).unwrap()
);
assert_eq!(
connection_string.options.heartbeat_interval,
IggyDuration::from_str(heartbeat_interval).unwrap()
);
assert_eq!(connection_string.options.nodelay, nodelay);
}
}
```
Could you kindle include some of these tests to at least cover the basic
functionality of parsing the connection string?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]