You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// trim non-numeric chars from the end of the port part of the line.
216
-
let port_str = line_end.trim_end_matches(|b:char| !b.is_ascii_digit());
215
+
// match the first group of digits
216
+
let re = regex::Regex::new(r"^\d+").expect("regex creation failed");
217
+
let port_capture = re
218
+
.captures(line_end)
219
+
.unwrap_or_else(|| panic!("unable to extract port from '{}'", line_end));
220
+
assert!(
221
+
port_capture.len() == 1,
222
+
"captured more than one port from '{}'",
223
+
line_end
224
+
);
225
+
let port_str = &port_capture[0];
217
226
218
227
// expect to have a number here (the chars after '127.0.0.1:') and parse them
219
228
// into a u16.
@@ -269,4 +278,25 @@ mod tests {
269
278
assert!(res1.is_err());
270
279
assert!(res2.is_err());
271
280
}
281
+
282
+
#[test]
283
+
fnparse_port_from_node_output(){
284
+
let log = "2024-12-04 10:57:03.893 INFO main sc_rpc_server: Running JSON-RPC server: addr=127.0.0.1:9944,[::1]:9944 ";
285
+
let port = find_substrate_port_from_output(log.as_bytes());
286
+
assert_eq!(port,9944);
287
+
288
+
let log = "2024-12-04 10:57:03.893 INFO main sc_rpc_server: Running JSON-RPC server: addr=127.0.0.1:9944 ";
289
+
let port = find_substrate_port_from_output(log.as_bytes());
290
+
assert_eq!(port,9944);
291
+
292
+
let log = r#"2024-12-04 11:02:24.637 INFO main sc_cli::runner: 👤 Role: AUTHORITY
293
+
2024-12-04 11:02:24.637 INFO main sc_cli::runner: 💾 Database: RocksDb at /var/folders/s5/5gcp8ck95k39z006fj059_0c0000gn/T/substrateHZoRbb/chains/dev/db/full
294
+
2024-12-04 11:02:25.324 WARN main sc_service::config: Using default protocol ID "sup" because none is configured in the chain specs
295
+
2024-12-04 11:02:25.327 INFO main sc_rpc_server: Running JSON-RPC server: addr=127.0.0.1:9944,[::1]:9944
296
+
2024-12-04 11:02:24.637 INFO main sc_cli::runner: 💾 Database: RocksDb at /var/folders/s5/5gcp8ck95k39z006fj059_0c0000gn/T/substrateHZoRbb/chains/dev/db/full
297
+
2024-12-04 11:02:24.637 INFO main sc_cli::runner: 💾 Database: RocksDb at /var/folders/s5/5gcp8ck95k39z006fj059_0c0000gn/T/substrateHZoRbb/chains/dev/db/full
298
+
"#;
299
+
let port = find_substrate_port_from_output(log.as_bytes());
0 commit comments