Skip to content

Commit 59a12b9

Browse files
cursoragentlovasoa
andcommitted
Refactor: Rename ssrp parsing functions and improve logging
Co-authored-by: contact <[email protected]>
1 parent a44d6de commit 59a12b9

File tree

1 file changed

+17
-13
lines changed
  • sqlx-core/src/mssql/connection

1 file changed

+17
-13
lines changed

sqlx-core/src/mssql/connection/ssrp.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ pub(crate) async fn resolve_instance_port(server: &str, instance: &str) -> Resul
109109

110110
log::debug!("SSRP response data: {}", response_str);
111111

112-
parse_ssrp_response(&response_str, instance)
112+
find_instance_tcp_port(&response_str, instance)
113113
}
114114

115-
fn parse_ssrp_response(data: &str, instance_name: &str) -> Result<u16, Error> {
115+
fn find_instance_tcp_port(data: &str, instance_name: &str) -> Result<u16, Error> {
116116
for instance_data in data.split(";;") {
117117
if instance_data.is_empty() {
118118
continue;
@@ -176,7 +176,11 @@ fn parse_instance_info<'a>(data: &'a str) -> InstanceInfo<'a> {
176176
"tcp" => {
177177
info.tcp_port = value.and_then(|v| v.parse::<u16>().ok());
178178
}
179-
_ => {}
179+
_ => {
180+
if !key.is_empty() {
181+
log::debug!("ignoring unknown SSRP key: '{}'", key);
182+
}
183+
}
180184
}
181185
}
182186

@@ -188,38 +192,38 @@ mod tests {
188192
use super::*;
189193

190194
#[test]
191-
fn test_parse_ssrp_response_single_instance() {
195+
fn test_find_instance_tcp_port_single_instance() {
192196
let data = "ServerName;MYSERVER;InstanceName;SQLEXPRESS;IsClustered;No;Version;15.0.2000.5;tcp;1433;;";
193-
let port = parse_ssrp_response(data, "SQLEXPRESS").unwrap();
197+
let port = find_instance_tcp_port(data, "SQLEXPRESS").unwrap();
194198
assert_eq!(port, 1433);
195199
}
196200

197201
#[test]
198-
fn test_parse_ssrp_response_multiple_instances() {
202+
fn test_find_instance_tcp_port_multiple_instances() {
199203
let data = "ServerName;SRV1;InstanceName;INST1;IsClustered;No;Version;15.0.2000.5;tcp;1433;;ServerName;SRV1;InstanceName;INST2;IsClustered;No;Version;16.0.1000.6;tcp;1434;np;\\\\SRV1\\pipe\\MSSQL$INST2\\sql\\query;;";
200-
let port = parse_ssrp_response(data, "INST2").unwrap();
204+
let port = find_instance_tcp_port(data, "INST2").unwrap();
201205
assert_eq!(port, 1434);
202206
}
203207

204208
#[test]
205-
fn test_parse_ssrp_response_case_insensitive() {
209+
fn test_find_instance_tcp_port_case_insensitive() {
206210
let data = "ServerName;MYSERVER;InstanceName;SQLExpress;IsClustered;No;Version;15.0.2000.5;tcp;1433;;";
207-
let port = parse_ssrp_response(data, "sqlexpress").unwrap();
211+
let port = find_instance_tcp_port(data, "sqlexpress").unwrap();
208212
assert_eq!(port, 1433);
209213
}
210214

211215
#[test]
212-
fn test_parse_ssrp_response_instance_not_found() {
216+
fn test_find_instance_tcp_port_instance_not_found() {
213217
let data = "ServerName;MYSERVER;InstanceName;SQLEXPRESS;IsClustered;No;Version;15.0.2000.5;tcp;1433;;";
214-
let result = parse_ssrp_response(data, "NOTFOUND");
218+
let result = find_instance_tcp_port(data, "NOTFOUND");
215219
assert!(result.is_err());
216220
}
217221

218222
#[test]
219-
fn test_parse_ssrp_response_no_tcp_port() {
223+
fn test_find_instance_tcp_port_no_tcp_port() {
220224
let data =
221225
"ServerName;MYSERVER;InstanceName;SQLEXPRESS;IsClustered;No;Version;15.0.2000.5;;";
222-
let result = parse_ssrp_response(data, "SQLEXPRESS");
226+
let result = find_instance_tcp_port(data, "SQLEXPRESS");
223227
assert!(result.is_err());
224228
}
225229
}

0 commit comments

Comments
 (0)