Skip to content
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

Fb tests #7

Merged
merged 6 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions l2-core/config
17 changes: 17 additions & 0 deletions l2-core/src/config/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ pub struct Client {
pub struct GSMessages {
pub timeout: u8,
}

#[cfg(test)]
mod tests {
use crate::config::login::LoginServer;
use crate::traits::ServerConfig;

#[test]
fn test_config_load() {
let cfg = LoginServer::load("../config/login.yaml");
assert_eq!(cfg.name, "login");
}
#[test]
#[should_panic(expected = "Failed to open config file: ./login.yaml. Error: No such file or directory (os error 2). Current directory: /Users/artem/dev/rust/L2Shablya/l2-core")]
fn test_config_load_err() {
LoginServer::load("./login.yaml");
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix test failures.

The test module has two issues:

  1. The assertion in test_config_load fails because the expected value doesn't match the actual value in the configuration file.
  2. The error test test_config_load_err is brittle due to hardcoded path in the expected error message.

Apply this diff to fix the assertion:

-        assert_eq!(cfg.name, "login");
+        assert_eq!(cfg.name, "Login server");

And refactor the error test to be more robust:

-    #[should_panic(expected = "Failed to open config file: ./login.yaml. Error: No such file or directory (os error 2). Current directory: /Users/artem/dev/rust/L2Shablya/l2-core")]
+    #[should_panic(expected = "Failed to open config file: ./login.yaml")]
     fn test_config_load_err() {
         LoginServer::load("./login.yaml");
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[cfg(test)]
mod tests {
use crate::config::login::LoginServer;
use crate::traits::ServerConfig;
#[test]
fn test_config_load() {
let cfg = LoginServer::load("../config/login.yaml");
assert_eq!(cfg.name, "login");
}
#[test]
#[should_panic(expected = "Failed to open config file: ./login.yaml. Error: No such file or directory (os error 2). Current directory: /Users/artem/dev/rust/L2Shablya/l2-core")]
fn test_config_load_err() {
LoginServer::load("./login.yaml");
}
}
#[cfg(test)]
mod tests {
use crate::config::login::LoginServer;
use crate::traits::ServerConfig;
#[test]
fn test_config_load() {
let cfg = LoginServer::load("../config/login.yaml");
assert_eq!(cfg.name, "Login server");
}
#[test]
#[should_panic(expected = "Failed to open config file: ./login.yaml")]
fn test_config_load_err() {
LoginServer::load("./login.yaml");
}
}
🧰 Tools
🪛 GitHub Actions: L2Shablya

[error] 114-114: Assertion failed: left == right. Left: "Login server", Right: "login".

13 changes: 12 additions & 1 deletion l2-core/src/config/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ pub trait ConfigDirLoader: Loadable + Default + LoadFileHandler {
#[cfg(test)]
mod test {
use super::*;
use crate as l2_core;
#[allow(unused_imports)]
use crate as l2_core; //hack to test l2_core crate
use macro_common::config_file;
use serde::Deserialize;

Expand All @@ -91,10 +92,20 @@ mod test {
struct TestConf {
name: String,
}
#[derive(Debug, Clone, Deserialize)]
#[config_file(path = "config/game.yaml", msg = "Loaded")]
struct TestConf2 {
name: String,
}

#[test]
fn test_config_file_loader() {
let conf = <TestConf as ConfigFileLoader>::load();
assert_eq!(conf.name, "test config");
}
#[test]
fn test_config_file_load() {
let conf = <TestConf2 as ConfigFileLoader>::load();
assert_eq!(conf.name, "Game server");
}
}
Loading