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