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::{Router, response::Json, routing::get};
7use oauth_provider_rs::{GitHubOAuthProvider, OAuthProvider, provider_trait::OAuthProviderConfig};
8use remote_mcp_kernel::microkernel::{
9    GitHubMicrokernelServer, MicrokernelServer, core::CustomRouterConfig,
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 = OAuthProviderConfig::with_oauth_config(
35        "test_client_id".to_string(),
36        "test_client_secret".to_string(),
37        "http://localhost:8080/oauth/callback".to_string(),
38        "read:user".to_string(),
39        "github".to_string(),
40    );
41
42    let github_oauth_provider = GitHubOAuthProvider::new_github(github_config);
43    let oauth_provider = OAuthProvider::new(
44        github_oauth_provider,
45        oauth_provider_rs::http_integration::config::OAuthProviderConfig::default(),
46    );
47
48    // Create custom routers
49    let health_router = Router::new().route("/health", get(health_check));
50
51    let api_router = Router::new().route("/status", get(api_status));
52
53    // Build microkernel server with custom routers
54    let microkernel: GitHubMicrokernelServer = MicrokernelServer::new()
55        .with_oauth_provider(oauth_provider)
56        .with_custom_router(health_router)
57        .with_custom_router_config(api_router, CustomRouterConfig::with_prefix("/api"));
58
59    // Test that the router can be built
60    let router = microkernel.build_router()?;
61    println!("โœ… Router built successfully!");
62
63    // Print available endpoints
64    println!("\n๐Ÿ“‹ Server would have these endpoints:");
65    println!("  OAuth:");
66    println!("    GET  /oauth/login");
67    println!("    GET  /oauth/callback");
68    println!("    POST /oauth/token");
69    println!("  Custom:");
70    println!("    GET  /health");
71    println!("    GET  /api/status");
72
73    println!("\n๐ŸŽ‰ Custom router functionality is working correctly!");
74    println!("   The server can be built and all routers are properly attached.");
75
76    Ok(())
77}