-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Use hive-24h logs as a realistic example log file for testing; …
…Add integration test for `LogParser`. (#15)
- Loading branch information
1 parent
4748bf9
commit 0e0dcbc
Showing
11 changed files
with
194 additions
and
50 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use log_surgeon::error_handling::Result; | ||
use log_surgeon::log_parser::LogParser; | ||
use log_surgeon::parser::SchemaConfig; | ||
|
||
use std::fs::File; | ||
use std::io::{self, BufRead}; | ||
|
||
#[test] | ||
fn test_lexer_simple() -> Result<()> { | ||
let project_root = env!("CARGO_MANIFEST_DIR"); | ||
let schema_path = std::path::Path::new(project_root) | ||
.join("examples") | ||
.join("schema.yaml"); | ||
let log_path = std::path::Path::new(project_root) | ||
.join("examples") | ||
.join("logs") | ||
.join("hive-24h.log"); | ||
|
||
let schema_config = SchemaConfig::parse_from_file(schema_path.to_str().unwrap())?; | ||
let mut log_parser = LogParser::new(schema_config)?; | ||
log_parser.set_input_file(log_path.to_str().unwrap())?; | ||
|
||
let mut actual = String::new(); | ||
let mut last_log_event_line_end = 0; | ||
while let Some(log_event) = log_parser.parse_next_log_event()? { | ||
let (start_line, end_line) = log_event.get_line_range(); | ||
assert_eq!(last_log_event_line_end + 1, start_line); | ||
last_log_event_line_end = end_line; | ||
actual += log_event.to_string().as_str(); | ||
} | ||
|
||
let mut expected = String::new(); | ||
let reader = io::BufReader::new(File::open(log_path).expect("failed to open log file")); | ||
for line in reader.lines() { | ||
let line = line.expect("failed to read line"); | ||
expected += line.as_str(); | ||
expected += "\n"; | ||
} | ||
|
||
assert_eq!(false, expected.is_empty()); | ||
assert_eq!(actual, expected); | ||
|
||
Ok(()) | ||
} |