-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests and refactor #73
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Streamer overlay local PORT | ||
pub const OVERLAY_PORT:&str = "47824"; | ||
|
||
// COHDB Auth | ||
pub const COHDB_CLIENT_ID:&str = "kHERjpU_rXcvgvLgwPir0w3bqcgETLOH-p95-PVxN-M"; | ||
pub const COHDB_REDIRECT_URI:&str = "coh3stats://cohdb.com/oauth/authorize"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod parse_log_file; | |
pub mod plugins; | ||
pub mod overlay_server; | ||
pub mod dp_utils; | ||
pub mod config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
use std::fs::File; | ||
use std::panic; | ||
use log::{error, info}; | ||
use std::fs::File; | ||
use std::path::PathBuf; | ||
|
||
use tiny_http::{Server, Response, StatusCode}; | ||
|
||
pub fn run_http_server(streamer_overlay_path: PathBuf) { | ||
|
||
let result = panic::catch_unwind(|| { | ||
use tiny_http::{Response, Server, StatusCode}; | ||
|
||
// Ideally we would allow setting up port in the settings | ||
info!("Starting streamer overlay server on port 47824"); | ||
let server = Server::http("127.0.0.1:47824").unwrap(); | ||
use crate::config::OVERLAY_PORT; | ||
|
||
for request in server.incoming_requests() { | ||
|
||
let file = match File::open(&streamer_overlay_path) { | ||
Ok(file) => file, | ||
Err(_) => { | ||
let response = Response::new_empty(StatusCode(404)); | ||
let _ = request.respond(response); | ||
continue; | ||
} | ||
}; | ||
|
||
let response = Response::from_file(file); | ||
let _ = request.respond(response); | ||
} | ||
|
||
}); | ||
pub fn run_http_server(streamer_overlay_path: PathBuf) { | ||
// Ideally we would allow setting up port in the settings | ||
info!("Starting streamer overlay server on port {}", OVERLAY_PORT); | ||
|
||
if let Err(err) = result { | ||
let server = match Server::http(format!("127.0.0.1:{}", OVERLAY_PORT)) { | ||
Ok(server) => server, | ||
Err(err) => { | ||
error!("Couldn't start the streamer overlay server: {:?}", err); | ||
} | ||
|
||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary to do here I'd say, but it probably makes sense to find all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}; | ||
|
||
for request in server.incoming_requests() { | ||
let file = match File::open(&streamer_overlay_path) { | ||
Ok(file) => file, | ||
Err(_) => { | ||
let response = Response::new_empty(StatusCode(404)); | ||
let _ = request.respond(response); | ||
continue; | ||
} | ||
}; | ||
|
||
let response = Response::from_file(file); | ||
let _ = request.respond(response); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::parse_log_file::{parse_log_file_reverse, GameState}; | ||
|
||
|
||
// TODO: Add more assertions and tests for parsing the log files | ||
|
||
#[test] | ||
fn test_parse_log_file_reverse_file_1() { | ||
// println!("{}", file!()); | ||
let result = parse_log_file_reverse("./test_assets/warnings-1.log".to_string()); | ||
assert_eq!(result.game_state, GameState::Closed); | ||
// can't compare for some reason | ||
// assert_eq!(result.game_type, GameType::Custom); | ||
|
||
assert_eq!(result.duration, 2217); | ||
assert_eq!(result.map, "winter_line_8p_mkii"); | ||
assert_eq!(result.win_condition, "VictoryPoint"); | ||
|
||
// assert some results | ||
// assert_eq!(result.len(), 3); | ||
// print!("{:#?}", result); | ||
} | ||
|
||
#[test] | ||
fn test_parse_log_file_reverse_file_2() { | ||
println!("{}", file!()); | ||
let result = parse_log_file_reverse("./test_assets/warnings-2.log".to_string()); | ||
assert_eq!(result.game_state, GameState::Closed); | ||
|
||
// TODO: add more assertions | ||
|
||
// print!("{:#?}", result); | ||
} | ||
|
||
#[test] | ||
fn test_parse_log_file_reverse_file_3() { | ||
println!("{}", file!()); | ||
let result = parse_log_file_reverse("./test_assets/warnings-3.log".to_string()); | ||
assert_eq!(result.game_state, GameState::Closed); | ||
|
||
assert_eq!(result.map, "desert_village_2p_mkiii"); | ||
// TODO: add more assertions | ||
|
||
|
||
// print!("{:#?}", result); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend adding
check
,fmt
, andclippy
here as well for some general linting of the Rust code. There's an example of the setup here: https://github.com/ryantaylor/vault/blob/master/.github/workflows/checks.ymlThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reported as #74