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

Fb tests #7

merged 6 commits into from
Feb 22, 2025

Conversation

artemijan
Copy link
Owner

@artemijan artemijan commented Feb 22, 2025

Summary by CodeRabbit

  • Chores
    • Updated configuration settings to streamline referencing of external files.
  • Tests
    • Added tests to verify proper loading of configuration files for both login and game services.
    • Included error handling tests to ensure robust behavior when configurations are missing or incorrect.
    • Enhanced test coverage with new test functions for successful and erroneous configuration loading.
    • Introduced a comprehensive testing framework for the Server trait, including mock implementations and test cases.

These updates enhance the system's reliability and ensure that configuration files are loaded and validated correctly.

Copy link

coderabbitai bot commented Feb 22, 2025

Walkthrough

This pull request establishes a reference to an external configuration folder by adding a relative path in the core config file. It introduces new test modules to verify the configuration loading functionality. In the login configuration file, tests check both successful loading and proper error handling. Additionally, a new test structure in another module verifies the loading of a separate YAML file. Changes to the Cargo.toml files across multiple packages shift the Rust edition to workspace support, while the char_create.rs file reorganizes import statements without affecting functionality.

Changes

File Path Changes
l2-core/config Added a new line that sets a relative path to the external configuration directory (../config/).
l2-core/src/config/(login.rs, traits.rs) Added new test modules:
• In login.rs: tests for successful and error cases when loading configurations.
• In traits.rs: a new struct TestConf2 and test for loading "config/game.yaml" along with an #[allow(unused_imports)] update.
Cargo.toml (multiple packages) Updated edition field to edition.workspace = true in the [package] section for l2-core, login, macro-common, migration, test-utils, and game packages.
game/src/packets/from_client/char_create.rs Reorganized import statement for std::sync::Arc to the tests module scope.
l2-core/src/dto.rs Updated Database and Runtime structs to derive Default trait.
l2-core/src/traits/server.rs Introduced a new test module with mock implementations and test cases for the Server trait.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test
    participant LS as LoginServer
    participant F as ConfigFile ("../config/login.yaml")
    
    T->>LS: Call load() for valid config
    LS->>F: Request YAML configuration
    F-->>LS: Return configuration with name "Login server"
    LS-->>T: Return config object
Loading
sequenceDiagram
    participant T as Test
    participant LS as LoginServer
    participant F as ConfigFile ("./login.yaml")
    
    T->>LS: Call load() for invalid config
    LS->>F: Attempt to access YAML file
    F-->>LS: File not found error
    LS-->>T: Panic with error message
Loading
sequenceDiagram
    participant T as Test
    participant TC as TestConf2
    participant F as ConfigFile ("config/game.yaml")

    T->>TC: Call load() for Game server config
    TC->>F: Request YAML configuration
    F-->>TC: Return configuration with name "Game server"
    TC-->>T: Return loaded configuration
Loading

Poem

I'm a bunny hopping through the code,
Skipping paths where configurations are strode.
New tests bloom like carrots in a row,
Checking loads whether fast or slow.
Hooray for clean code—watch my ears glow!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1b752 and 6d8c8d0.

📒 Files selected for processing (3)
  • l2-core/config (1 hunks)
  • l2-core/src/config/login.rs (1 hunks)
  • l2-core/src/config/traits.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • l2-core/config
🧰 Additional context used
🪛 GitHub Actions: L2Shablya
l2-core/src/config/login.rs

[error] 28-28: Failed to open config file: ./login.yaml. Error: No such file or directory (os error 2).


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

🔇 Additional comments (2)
l2-core/src/config/traits.rs (2)

85-86: LGTM!

The import hack is a common pattern in Rust for testing macros within the same crate.


95-110:

✅ Verification successful

Verify the configuration file path and expected value.

The test implementation looks good. However, ensure that:

  1. The configuration file exists at config/game.yaml relative to the repository root.
  2. The configuration file contains the expected value "Game server" for the name field.

🏁 Script executed:

#!/bin/bash
# Description: Verify the configuration file and its content.

# Test: Check if the configuration file exists
if [ -f "config/game.yaml" ]; then
  echo "Configuration file exists"
  # Test: Check if the configuration file contains the expected value
  if grep -q "name: Game server" "config/game.yaml"; then
    echo "Configuration file contains the expected value"
  else
    echo "Configuration file does not contain the expected value"
  fi
else
  echo "Configuration file does not exist"
fi

Length of output: 240


Configuration file and test assertions confirmed.

The configuration file exists at config/game.yaml and contains the expected value "Game server" for the name field. The new test struct and function (TestConf2 and test_config_file_load) correctly follow the established pattern.

Comment on lines 106 to 121
#[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".

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
l2-core/src/traits/server.rs (1)

167-348: Well-structured test module with comprehensive mocking.

The test module provides good coverage of the Server trait functionality with appropriate mocks and test cases.

Consider implementing critical mock methods.

While todo!() is acceptable for most mock methods, consider implementing critical methods that might be needed for future tests:

  • handle_client()
  • on_connect()
  • on_disconnect()
 async fn handle_client(&mut self) -> anyhow::Result<()> {
-    todo!()
+    Ok(())
 }

 async fn on_connect(&mut self) -> anyhow::Result<()> {
-    todo!()
+    Ok(())
 }

 async fn on_disconnect(&mut self) {
-    todo!()
+    // No-op implementation
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3918b0f and e1a2943.

📒 Files selected for processing (11)
  • Cargo.toml (1 hunks)
  • entities/Cargo.toml (1 hunks)
  • game/Cargo.toml (1 hunks)
  • game/src/packets/from_client/char_create.rs (1 hunks)
  • l2-core/Cargo.toml (1 hunks)
  • l2-core/src/dto.rs (2 hunks)
  • l2-core/src/traits/server.rs (1 hunks)
  • login/Cargo.toml (1 hunks)
  • macro-common/Cargo.toml (1 hunks)
  • migration/Cargo.toml (1 hunks)
  • test-utils/Cargo.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • game/src/packets/from_client/char_create.rs
🔇 Additional comments (10)
l2-core/src/dto.rs (1)

7-7: LGTM! Good addition of Default trait.

Adding the Default trait to Database and Runtime structs enhances their usability in testing scenarios by allowing partial initialization of these configuration structures.

Also applies to: 33-33

test-utils/Cargo.toml (1)

4-4: LGTM! Good workspace configuration update.

Moving to workspace-level edition configuration improves consistency across the project.

macro-common/Cargo.toml (1)

4-4: LGTM! Good workspace configuration update.

Moving to workspace-level edition configuration improves consistency across the project.

entities/Cargo.toml (1)

4-4: Review the Workspace Edition Directive
The replacement of the traditional edition field with edition.workspace = true signals an intention to inherit the Rust edition from the workspace configuration. Please verify that your Cargo tooling and workspace settings support this new directive and that it behaves as expected across your workspace.

migration/Cargo.toml (1)

4-4: Confirm Workspace Edition Configuration in Migration Package
The modified line using edition.workspace = true in the [package] section should ensure that the migration package adheres to the workspace’s edition settings. Double-check that any workspace-level configurations are correctly applied and that this syntax is supported by your Cargo version.

login/Cargo.toml (1)

4-4: Verify Workspace Edition Setting for Login Package
Switching to edition.workspace = true aligns this package with the workspace’s configuration. Please confirm that this change integrates correctly with the overall workspace settings and that there are no unintended side effects with dependency resolution or compilation.

game/Cargo.toml (1)

4-4: Review Workspace Edition Usage in Game Package
The change to edition.workspace = true is consistent with the new workspace-centric approach. Ensure that the game package now correctly inherits the Rust edition from the workspace and that your build environment supports this configuration.

l2-core/Cargo.toml (1)

4-4: Assess the Workspace Edition Directive in l2-core
The alteration to edition.workspace = true is intended to unify the edition setting across the workspace. Verify that this directive is compatible with your Cargo setup and that all team members are aware of the change in configuration management for editions.

Cargo.toml (2)

1-3: New Workspace Package Configuration Added

The addition of a [workspace.package] section with edition = "2021" provides a unified Rust edition configuration for the workspace. This change helps ensure consistency across all workspace packages. Please verify that your local Cargo version supports this configuration for smooth builds.


8-8: Improved Formatting with a Newline

An empty newline was added at line 8 to separate sections and enhance readability. This minor formatting update helps visually organize the file.

@artemijan artemijan merged commit 9ef5c80 into master Feb 22, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant