62 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
use std::net::SocketAddr;
 | 
						|
use jsonrpsee::http_client::HttpClientBuilder;
 | 
						|
use jsonrpsee::core::client::ClientT;
 | 
						|
use serde_json::json;
 | 
						|
 | 
						|
use herodb::rpc::{RpcClient, BackendType, DatabaseConfig};
 | 
						|
 | 
						|
#[tokio::test]
 | 
						|
async fn test_rpc_server_basic() {
 | 
						|
    // This test would require starting the RPC server in a separate thread
 | 
						|
    // For now, we'll just test that the types compile correctly
 | 
						|
 | 
						|
    // Test serialization of types
 | 
						|
    let backend = BackendType::Redb;
 | 
						|
    let config = DatabaseConfig {
 | 
						|
        name: Some("test_db".to_string()),
 | 
						|
        storage_path: Some("/tmp/test".to_string()),
 | 
						|
        max_size: Some(1024 * 1024),
 | 
						|
        redis_version: Some("7.0".to_string()),
 | 
						|
    };
 | 
						|
 | 
						|
    let backend_json = serde_json::to_string(&backend).unwrap();
 | 
						|
    let config_json = serde_json::to_string(&config).unwrap();
 | 
						|
 | 
						|
    assert_eq!(backend_json, "\"Redb\"");
 | 
						|
    assert!(config_json.contains("test_db"));
 | 
						|
}
 | 
						|
 | 
						|
#[tokio::test]
 | 
						|
async fn test_database_config_serialization() {
 | 
						|
    let config = DatabaseConfig {
 | 
						|
        name: Some("my_db".to_string()),
 | 
						|
        storage_path: None,
 | 
						|
        max_size: Some(1000000),
 | 
						|
        redis_version: Some("7.0".to_string()),
 | 
						|
    };
 | 
						|
 | 
						|
    let json = serde_json::to_value(&config).unwrap();
 | 
						|
    assert_eq!(json["name"], "my_db");
 | 
						|
    assert_eq!(json["max_size"], 1000000);
 | 
						|
    assert_eq!(json["redis_version"], "7.0");
 | 
						|
}
 | 
						|
 | 
						|
#[tokio::test]
 | 
						|
async fn test_backend_type_serialization() {
 | 
						|
    // Test that both Redb and Sled backends serialize correctly
 | 
						|
    let redb_backend = BackendType::Redb;
 | 
						|
    let sled_backend = BackendType::Sled;
 | 
						|
 | 
						|
    let redb_json = serde_json::to_string(&redb_backend).unwrap();
 | 
						|
    let sled_json = serde_json::to_string(&sled_backend).unwrap();
 | 
						|
 | 
						|
    assert_eq!(redb_json, "\"Redb\"");
 | 
						|
    assert_eq!(sled_json, "\"Sled\"");
 | 
						|
 | 
						|
    // Test deserialization
 | 
						|
    let redb_deserialized: BackendType = serde_json::from_str(&redb_json).unwrap();
 | 
						|
    let sled_deserialized: BackendType = serde_json::from_str(&sled_json).unwrap();
 | 
						|
 | 
						|
    assert!(matches!(redb_deserialized, BackendType::Redb));
 | 
						|
    assert!(matches!(sled_deserialized, BackendType::Sled));
 | 
						|
} |