Add comprehensive documentation and unit tests

Documentation:
- Add detailed README files for all services (auth, character, database, launcher, packet, utils, world)
- Create API documentation for the database service with detailed endpoint specifications
- Document database schema and relationships
- Add service architecture overviews and configuration instructions

Unit Tests:
- Implement comprehensive test suite for database repositories (user, character, session)
- Add gRPC service tests for database interactions
- Create tests for packet service components (bufferpool, connection, packets)
- Add utility service tests (health check, logging, load balancer, redis cache, service discovery)
- Implement auth service user tests
- Add character service tests

Code Structure:
- Reorganize test files into a more consistent structure
- Create a dedicated tests crate for integration testing
- Add test helpers and mock implementations for easier testing
This commit is contained in:
2025-04-09 13:29:38 -04:00
parent d47d5f44b1
commit a8755bd3de
85 changed files with 4218 additions and 764 deletions

View File

@@ -1,9 +1,8 @@
use crate::database::character_db_service_client::CharacterDbServiceClient;
use crate::database::{
Character, CharacterListRequest, CharacterListResponse, CharacterRequest,
CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest,
DeleteCharacterResponse,
character_db_service_client::CharacterDbServiceClient, Character, CharacterListRequest, CharacterListResponse,
CharacterRequest, CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest, DeleteCharacterResponse,
};
use serde::{Deserialize, Serialize};
use tonic::transport::Channel;

View File

@@ -1,9 +1,8 @@
use crate::character_db_client::CharacterDbClient;
use crate::character_service::character::character_service_server::CharacterService;
use crate::character_service::character::{
CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest,
DeleteCharacterResponse, GetCharacterListRequest, GetCharacterListResponse,
GetCharacterRequest, GetCharacterResponse,
CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest, DeleteCharacterResponse,
GetCharacterListRequest, GetCharacterListResponse, GetCharacterRequest, GetCharacterResponse,
};
use crate::character_service::character_common::{Character, CharacterFull};
use std::sync::Arc;
@@ -69,14 +68,7 @@ impl CharacterService for MyCharacterService {
.character_db_client
.as_ref()
.clone()
.create_character(
&req.user_id,
&req.name,
req.race,
req.face,
req.hair,
req.stone,
)
.create_character(&req.user_id, &req.name, req.race, req.face, req.hair, req.stone)
.await
.map_err(|_| Status::aborted("Unable to create character"))?;

View File

@@ -0,0 +1,5 @@
// Include the generated code
tonic::include_proto!("character_db_api");
// Re-export the types we need
pub use character_db_service_client::CharacterDbServiceClient;

View File

@@ -0,0 +1,3 @@
pub mod character_db_client;
pub mod character_service;
pub mod database;

View File

@@ -14,7 +14,7 @@ use std::sync::Arc;
use tracing::Level;
use tracing_subscriber::EnvFilter;
use utils::logging;
use utils::service_discovery::{get_kube_service_endpoints_by_dns};
use utils::service_discovery::get_kube_service_endpoints_by_dns;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -25,17 +25,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Set the gRPC server address
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
let port = env::var("SERVICE_PORT").unwrap_or_else(|_| "50053".to_string());
let db_url = format!("http://{}",get_kube_service_endpoints_by_dns("database-service","tcp","database-service").await?.get(0).unwrap());
let db_url = format!(
"http://{}",
get_kube_service_endpoints_by_dns("database-service", "tcp", "database-service")
.await?
.get(0)
.unwrap()
);
let full_addr = format!("{}:{}", &addr, port);
let address = full_addr.parse().expect("Invalid address");
let character_db_client = Arc::new(CharacterDbClient::connect(&db_url).await?);
let character_service = MyCharacterService {
character_db_client,
};
let character_service = MyCharacterService { character_db_client };
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
health_reporter.set_serving::<CharacterServiceServer<MyCharacterService>>().await;
health_reporter
.set_serving::<CharacterServiceServer<MyCharacterService>>()
.await;
tonic::transport::Server::builder()
.add_service(health_service)