Skip to content

Commit

Permalink
test: [torrust#884] add test for parsing array of services from app logs
Browse files Browse the repository at this point in the history
The tracker can run multiple UDP or HTTP trackers. We parse the services
from app output but there was not test for multiple services of the same
type (UDP or HTTP tracker).
  • Loading branch information
josecelano authored and da2ce7 committed Jun 20, 2024
1 parent 4e7b773 commit 08233b0
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions src/console/ci/e2e/logs_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ impl RunningServices {
///
/// ```text
/// Loading configuration from default configuration file: `./share/default/config/tracker.development.sqlite3.toml` ...
/// 2024-06-10T14:59:57.973525Z INFO torrust_tracker::bootstrap::logging: logging initialized.
/// 2024-06-10T14:59:57.974306Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6969
/// 2024-06-10T14:59:57.974316Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6969
/// 2024-06-10T14:59:57.974332Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
/// 2024-06-10T14:59:57.974366Z INFO HTTP TRACKER: Starting on: http://0.0.0.0:7070
/// 2024-06-10T14:59:57.974513Z INFO HTTP TRACKER: Started on: http://0.0.0.0:7070
/// 2024-06-10T14:59:57.974521Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
/// 2024-06-10T14:59:57.974615Z INFO API: Starting on http://127.0.0.1:1212
/// 2024-06-10T14:59:57.974618Z INFO API: Started on http://127.0.0.1:1212
/// 2024-06-10T14:59:57.974643Z INFO HEALTH CHECK API: Starting on: http://127.0.0.1:1313
/// 2024-06-10T14:59:57.974760Z INFO HEALTH CHECK API: Started on: http://127.0.0.1:1313
/// 2024-06-10T16:07:39.989540Z INFO torrust_tracker::bootstrap::logging: logging initialized.
/// 2024-06-10T16:07:39.990205Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6868
/// 2024-06-10T16:07:39.990215Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6868
/// 2024-06-10T16:07:39.990244Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6969
/// 2024-06-10T16:07:39.990255Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6969
/// 2024-06-10T16:07:39.990261Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
/// 2024-06-10T16:07:39.990303Z INFO HTTP TRACKER: Starting on: http://0.0.0.0:7070
/// 2024-06-10T16:07:39.990439Z INFO HTTP TRACKER: Started on: http://0.0.0.0:7070
/// 2024-06-10T16:07:39.990448Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
/// 2024-06-10T16:07:39.990563Z INFO API: Starting on http://127.0.0.1:1212
/// 2024-06-10T16:07:39.990565Z INFO API: Started on http://127.0.0.1:1212
/// 2024-06-10T16:07:39.990577Z INFO HEALTH CHECK API: Starting on: http://127.0.0.1:1313
/// 2024-06-10T16:07:39.990638Z INFO HEALTH CHECK API: Started on: http://127.0.0.1:1313
/// ```
///
/// It would extract these services:
Expand All @@ -48,7 +50,7 @@ impl RunningServices {
/// }
/// ```
///
/// NOTICE: Using colors in the console output could affect this method
/// NOTICE: Using colors in the console output could affect this method
/// due to the hidden control chars.
#[must_use]
pub fn parse_from_logs(logs: &str) -> Self {
Expand Down Expand Up @@ -89,7 +91,7 @@ mod tests {

#[test]
fn it_should_parse_from_logs_with_valid_logs() {
let log = r#"
let logs = r#"
Loading configuration from environment variable db_path = "/var/lib/torrust/tracker/database/sqlite3.db"
[[udp_trackers]]
Expand All @@ -103,22 +105,22 @@ mod tests {
[http_api]
ssl_cert_path = "/var/lib/torrust/tracker/tls/localhost.crt"
ssl_key_path = "/var/lib/torrust/tracker/tls/localhost.key"
...
Loading configuration from file: `/etc/torrust/tracker/tracker.toml` ...
2024-06-10T15:09:54.411031Z INFO torrust_tracker::bootstrap::logging: logging initialized.
2024-06-10T15:09:54.415084Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6969
2024-06-10T15:09:54.415091Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6969
2024-06-10T15:09:54.415104Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
2024-06-10T15:09:54.415130Z INFO HTTP TRACKER: Starting on: http://0.0.0.0:7070
2024-06-10T15:09:54.415266Z INFO HTTP TRACKER: Started on: http://0.0.0.0:7070
2024-06-10T15:09:54.415275Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
2024-06-10T15:09:54.415403Z INFO API: Starting on http://127.0.0.1:1212
2024-06-10T15:09:54.415411Z INFO API: Started on http://127.0.0.1:1212
2024-06-10T15:09:54.415430Z INFO HEALTH CHECK API: Starting on: http://127.0.0.1:1313
2024-06-10T15:09:54.415472Z INFO HEALTH CHECK API: Started on: http://127.0.0.1:1313
Loading configuration from default configuration file: `./share/default/config/tracker.development.sqlite3.toml` ...
2024-06-10T16:07:39.989540Z INFO torrust_tracker::bootstrap::logging: logging initialized.
2024-06-10T16:07:39.990244Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6969
2024-06-10T16:07:39.990255Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6969
2024-06-10T16:07:39.990261Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
2024-06-10T16:07:39.990303Z INFO HTTP TRACKER: Starting on: http://0.0.0.0:7070
2024-06-10T16:07:39.990439Z INFO HTTP TRACKER: Started on: http://0.0.0.0:7070
2024-06-10T16:07:39.990448Z INFO torrust_tracker::bootstrap::jobs: TLS not enabled
2024-06-10T16:07:39.990563Z INFO API: Starting on http://127.0.0.1:1212
2024-06-10T16:07:39.990565Z INFO API: Started on http://127.0.0.1:1212
2024-06-10T16:07:39.990577Z INFO HEALTH CHECK API: Starting on: http://127.0.0.1:1313
2024-06-10T16:07:39.990638Z INFO HEALTH CHECK API: Started on: http://127.0.0.1:1313
"#;

let running_services = RunningServices::parse_from_logs(log);
let running_services = RunningServices::parse_from_logs(logs);

assert_eq!(running_services.udp_trackers, vec!["127.0.0.1:6969"]);
assert_eq!(running_services.http_trackers, vec!["http://127.0.0.1:7070"]);
Expand All @@ -128,13 +130,29 @@ mod tests {
#[test]
fn it_should_ignore_logs_with_no_matching_lines() {
let logs = "[Other Service][INFO] Started on: 0.0.0.0:7070";

let running_services = RunningServices::parse_from_logs(logs);

assert!(running_services.udp_trackers.is_empty());
assert!(running_services.http_trackers.is_empty());
assert!(running_services.health_checks.is_empty());
}

#[test]
fn it_should_parse_multiple_services() {
let logs = "
2024-06-10T16:07:39.990205Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6868
2024-06-10T16:07:39.990215Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6868
2024-06-10T16:07:39.990244Z INFO UDP TRACKER: Starting on: udp://0.0.0.0:6969
2024-06-10T16:07:39.990255Z INFO UDP TRACKER: Started on: udp://0.0.0.0:6969
";

let running_services = RunningServices::parse_from_logs(logs);

assert_eq!(running_services.udp_trackers, vec!["127.0.0.1:6868", "127.0.0.1:6969"]);
}

#[test]
fn it_should_replace_wildcard_ip_with_localhost() {
let address = "0.0.0.0:8080";
Expand Down

0 comments on commit 08233b0

Please sign in to comment.