spetz commented on code in PR #1803:
URL: https://github.com/apache/iggy/pull/1803#discussion_r2112370142
##########
core/sdk/src/http/http_client.rs:
##########
@@ -325,3 +335,203 @@ impl HttpClient {
struct RefreshToken {
token: String,
}
+
+/// Unit tests for HttpClient.
+/// Currently only tests for "from_connection_string()" are implemented.
+/// TODO: Add complete unit tests for HttpClient.
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn should_fail_with_empty_connection_string() {
+ let value = "";
+ let http_client = HttpClient::from_connection_string(value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_fail_without_username() {
+ let connection_string_prefix = "iggy+";
+ let protocol = TransportProtocol::Http;
+ let server_address = "127.0.0.1";
+ let port = "1234";
+ let username = "";
+ let password = "secret";
+ let value = format!(
+
"{connection_string_prefix}{protocol}://{username}:{password}@{server_address}:{port}"
+ );
+ let http_client = HttpClient::from_connection_string(&value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_fail_without_password() {
+ let connection_string_prefix = "iggy+";
+ let protocol = TransportProtocol::Http;
+ let server_address = "127.0.0.1";
+ let port = "1234";
+ let username = "user";
+ let password = "";
+ let value = format!(
+
"{connection_string_prefix}{protocol}://{username}:{password}@{server_address}:{port}"
+ );
+ let http_client = HttpClient::from_connection_string(&value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_fail_without_server_address() {
+ let connection_string_prefix = "iggy+";
+ let protocol = TransportProtocol::Http;
+ let server_address = "";
+ let port = "1234";
+ let username = "user";
+ let password = "secret";
+ let value = format!(
+
"{connection_string_prefix}{protocol}://{username}:{password}@{server_address}:{port}"
+ );
+ let http_client = HttpClient::from_connection_string(&value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_fail_without_port() {
+ let connection_string_prefix = "iggy+";
+ let protocol = TransportProtocol::Http;
+ let server_address = "127.0.0.1";
+ let port = "";
+ let username = "user";
+ let password = "secret";
+ let value = format!(
+
"{connection_string_prefix}{protocol}://{username}:{password}@{server_address}:{port}"
+ );
+ let http_client = HttpClient::from_connection_string(&value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_fail_with_invalid_prefix() {
+ let connection_string_prefix = "invalid+";
+ let protocol = TransportProtocol::Http;
+ let server_address = "127.0.0.1";
+ let port = "1234";
+ let username = "user";
+ let password = "secret";
+ let value = format!(
+
"{connection_string_prefix}{protocol}://{username}:{password}@{server_address}:{port}"
+ );
+ let http_client = HttpClient::from_connection_string(&value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_fail_with_unmatch_protocol() {
+ let connection_string_prefix = "iggy+";
+ let protocol = TransportProtocol::Quic;
+ let server_address = "127.0.0.1";
+ let port = "1234";
+ let username = "user";
+ let password = "secret";
+ let value = format!(
+
"{connection_string_prefix}{protocol}://{username}:{password}@{server_address}:{port}"
+ );
+ let http_client = HttpClient::from_connection_string(&value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_fail_with_default_prefix() {
+ let default_connection_string_prefix = "iggy://";
+ let server_address = "127.0.0.1";
+ let port = "1234";
+ let username = "user";
+ let password = "secret";
+ let value = format!(
+
"{default_connection_string_prefix}{username}:{password}@{server_address}:{port}"
+ );
+ let http_client = HttpClient::from_connection_string(&value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_fail_with_invalid_options() {
+ let connection_string_prefix = "iggy+";
+ let protocol = TransportProtocol::Http;
+ let server_address = "127.0.0.1";
+ let port = "";
+ let username = "user";
+ let password = "secret";
+ let value = format!(
+
"{connection_string_prefix}{protocol}://{username}:{password}@{server_address}:{port}?invalid_option=invalid"
+ );
+ let http_client = HttpClient::from_connection_string(&value);
+ assert!(http_client.is_err());
+ }
+
+ #[test]
+ fn should_success_without_options() {
Review Comment:
These ok tests should be named `should_succeed` (not success).
--
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]