simple_custom_router_test/
simple_custom_router_test.rs

1//! Simple test to verify custom router functionality works correctly
2//!
3//! This is a minimal test that creates a server, attaches custom routers,
4//! and verifies the router can be built without errors.
5
6use axum::{response::Json, routing::get, Router};
7use oauth_provider_rs::{GitHubOAuthConfig, GitHubOAuthProvider, OAuthProvider};
8use remote_mcp_kernel::microkernel::{
9    core::CustomRouterConfig, GitHubMicrokernelServer, MicrokernelServer,
10};
11use serde_json::json;
12
13/// Simple health check endpoint
14async fn health_check() -> Json<serde_json::Value> {
15    Json(json!({
16        "status": "healthy",
17        "service": "test"
18    }))
19}
20
21/// Simple API endpoint
22async fn api_status() -> Json<serde_json::Value> {
23    Json(json!({
24        "api": "working",
25        "version": "1.0"
26    }))
27}
28
29#[tokio::main]
30async fn main() -> Result<(), Box<dyn std::error::Error>> {
31    println!("๐Ÿงช Testing custom router functionality...");
32
33    // Create OAuth provider
34    let github_config = GitHubOAuthConfig {
35        client_id: "test_client_id".to_string(),
36        client_secret: "test_client_secret".to_string(),
37        redirect_uri: "http://localhost:8080/oauth/callback".to_string(),
38        scope: "read:user".to_string(),
39        provider_name: "github".to_string(),
40    };
41
42    let github_oauth_provider = GitHubOAuthProvider::new_github(github_config);
43    let oauth_provider = OAuthProvider::new(github_oauth_provider);
44
45    // Create custom routers
46    let health_router = Router::new()
47        .route("/health", get(health_check));
48
49    let api_router = Router::new()
50        .route("/status", get(api_status));
51
52    // Build microkernel server with custom routers
53    let microkernel: GitHubMicrokernelServer = MicrokernelServer::new()
54        .with_oauth_provider(oauth_provider)
55        .with_custom_router(health_router)
56        .with_custom_router_config(
57            api_router,
58            CustomRouterConfig::with_prefix("/api"),
59        );
60
61    // Test that the router can be built
62    let router = microkernel.build_router()?;
63    println!("โœ… Router built successfully!");
64
65    // Print available endpoints
66    println!("\n๐Ÿ“‹ Server would have these endpoints:");
67    println!("  OAuth:");
68    println!("    GET  /oauth/login");
69    println!("    GET  /oauth/callback");
70    println!("    POST /oauth/token");
71    println!("  Custom:");
72    println!("    GET  /health");
73    println!("    GET  /api/status");
74    
75    println!("\n๐ŸŽ‰ Custom router functionality is working correctly!");
76    println!("   The server can be built and all routers are properly attached.");
77
78    Ok(())
79}