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
109 lines
3.5 KiB
Rust
109 lines
3.5 KiB
Rust
use packet_service::connection_service::ConnectionService;
|
|
use packet_service::connection_state::ConnectionState;
|
|
use std::collections::HashSet;
|
|
|
|
#[test]
|
|
fn test_connection_service_add_connection() {
|
|
let service = ConnectionService::new();
|
|
|
|
// Add a connection
|
|
let connection_id = service.add_connection();
|
|
|
|
// Verify the connection exists
|
|
let connection = service.get_connection(&connection_id);
|
|
assert!(connection.is_some());
|
|
}
|
|
|
|
#[test]
|
|
fn test_connection_service_remove_connection() {
|
|
let service = ConnectionService::new();
|
|
|
|
// Add a connection
|
|
let connection_id = service.add_connection();
|
|
|
|
// Verify the connection exists
|
|
let connection = service.get_connection(&connection_id);
|
|
assert!(connection.is_some());
|
|
|
|
// Remove the connection
|
|
service.remove_connection(&connection_id);
|
|
|
|
// Verify the connection no longer exists
|
|
let connection = service.get_connection(&connection_id);
|
|
assert!(connection.is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn test_connection_service_get_connection_mut() {
|
|
let service = ConnectionService::new();
|
|
|
|
// Add a connection
|
|
let connection_id = service.add_connection();
|
|
|
|
// Get a mutable reference to the connection
|
|
let mut connection = service.get_connection_mut(&connection_id).unwrap();
|
|
|
|
// Modify the connection
|
|
connection.user_id = Some("test_user".to_string());
|
|
connection.session_id = Some("test_session".to_string());
|
|
connection.character_id = Some(123);
|
|
|
|
// Drop the mutable reference
|
|
drop(connection);
|
|
|
|
// Verify the changes were saved
|
|
let connection = service.get_connection(&connection_id).unwrap();
|
|
assert_eq!(connection.user_id, Some("test_user".to_string()));
|
|
assert_eq!(connection.session_id, Some("test_session".to_string()));
|
|
assert_eq!(connection.character_id, Some(123));
|
|
}
|
|
|
|
#[test]
|
|
fn test_connection_service_multiple_connections() {
|
|
let service = ConnectionService::new();
|
|
|
|
// Add multiple connections
|
|
let connection_ids: Vec<String> = (0..10).map(|_| service.add_connection()).collect();
|
|
|
|
// Verify all connections exist
|
|
for connection_id in &connection_ids {
|
|
let connection = service.get_connection(connection_id);
|
|
assert!(connection.is_some());
|
|
}
|
|
|
|
// Verify all connection IDs are unique
|
|
let unique_ids: HashSet<String> = connection_ids.iter().cloned().collect();
|
|
assert_eq!(unique_ids.len(), connection_ids.len());
|
|
}
|
|
|
|
#[test]
|
|
fn test_connection_state_new() {
|
|
let state = ConnectionState::new();
|
|
|
|
// Verify initial state
|
|
assert_eq!(state.user_id, None);
|
|
assert_eq!(state.session_id, None);
|
|
assert_eq!(state.character_id, None);
|
|
assert_eq!(state.character_list, None);
|
|
assert!(state.additional_data.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn test_connection_state_additional_data() {
|
|
let mut state = ConnectionState::new();
|
|
|
|
// Add some additional data
|
|
state.additional_data.insert("key1".to_string(), "value1".to_string());
|
|
state.additional_data.insert("key2".to_string(), "value2".to_string());
|
|
|
|
// Verify the data was added
|
|
assert_eq!(state.additional_data.get("key1"), Some(&"value1".to_string()));
|
|
assert_eq!(state.additional_data.get("key2"), Some(&"value2".to_string()));
|
|
|
|
// Update a value
|
|
state.additional_data.insert("key1".to_string(), "updated".to_string());
|
|
|
|
// Verify the value was updated
|
|
assert_eq!(state.additional_data.get("key1"), Some(&"updated".to_string()));
|
|
}
|