product-os-server 0.0.55

Product OS : Server provides a full functioning advanced server capable of acting as a web server, command and control distributed network, authentication server, crawling server and more. Fully featured with high level of flexibility.
Documentation
//! API Compatibility Tests
//! 
//! These tests ensure that all public APIs remain accessible and functional,
//! preventing accidental breaking changes.

#![cfg(feature = "executor_tokio")]

use product_os_server::{ProductOSServer, ProductOSServerError};
use product_os_async_executor::TokioExecutor;
use product_os_server::ServerConfig;

/// Test that ProductOSServer can be constructed with default config
#[tokio::test]
async fn test_new_with_config() {
    let config = ServerConfig::new();
    let _server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    // Construction should succeed
}

/// Test that ProductOSServer can be constructed with custom state
#[tokio::test]
async fn test_new_with_state() {
    #[derive(Clone)]
    struct AppState {
        #[allow(dead_code)]
        counter: i32,
    }
    
    let state = AppState { counter: 0 };
    let _server: ProductOSServer<AppState, TokioExecutor, _> = ProductOSServer::new_with_state(state);
    // Construction should succeed
}

/// Test that ProductOSServer can be constructed with state and config
#[tokio::test]
async fn test_new_with_state_with_config() {
    #[derive(Clone)]
    struct AppState {
        #[allow(dead_code)]
        value: String,
    }
    
    let state = AppState { value: "test".to_string() };
    let config = ServerConfig::new();
    let _server: ProductOSServer<AppState, TokioExecutor, _> = 
        ProductOSServer::new_with_state_with_config(config, state);
    // Construction should succeed
}

/// Test router access
#[tokio::test]
async fn test_get_router() {
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    let _router = server.get_router();
    // Router should be accessible
}

/// Test config access and update
#[tokio::test]
async fn test_config_operations() {
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config.clone());
    
    let retrieved_config = server.get_config();
    assert_eq!(retrieved_config.network.host, config.network.host);
    
    let new_config = ServerConfig::new();
    server.update_config(new_config);
    // Config operations should work
}

/// Test adding routes
#[tokio::test]
async fn test_add_route() {
    use product_os_server::{StatusCode, Response, Body};
    
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    async fn handler() -> Result<Response<Body>, StatusCode> {
        Ok(Response::new(Body::empty()))
    }
    
    server.add_get("/test", handler);
    // Route addition should succeed
}

/// Test setting fallback handler
#[tokio::test]
async fn test_set_fallback_handler() {
    use product_os_server::{StatusCode, Response, Body};
    
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    async fn fallback_handler() -> Result<Response<Body>, StatusCode> {
        Ok(Response::builder()
            .status(StatusCode::NOT_FOUND)
            .body(Body::empty())
            .unwrap())
    }
    
    server.set_fallback_handler(fallback_handler);
    // Fallback should be set successfully
}

/// Test middleware addition
#[tokio::test]
async fn test_add_middleware() {
    let config = ServerConfig::new();
    let _server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    // Test that middleware can be added (compile-time check)
    // Actual middleware implementation would be more complex
}

/// Test certificate configuration
#[cfg(feature = "security_certificates")]
#[tokio::test]
async fn test_set_certificate() {
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    server.set_certificate(&None);
    // Certificate setting should work
}

/// Test security configuration
#[tokio::test]
async fn test_set_security() {
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    server.set_security(None);
    // Security setting should work
}

/// Test logging configuration
#[tokio::test]
async fn test_set_logging() {
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    server.set_logging(tracing::Level::INFO);
    // Logging setting should work
}

/// Test base URL retrieval
#[tokio::test]
#[allow(deprecated)]
async fn test_get_base_url() {
    let mut config = ServerConfig::new();
    config.network.protocol = "http".to_string();
    config.network.host = "localhost".to_string();
    config.network.port = 3000;
    let server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    let base_url = server.get_base_url();
    assert!(base_url.to_string().contains("localhost"));
    // Base URL should be retrievable
}

/// Test error type is accessible
#[test]
fn test_error_type() {
    let _error = ProductOSServerError::GenericError("test".to_string());
    // Error type should be constructible
}

#[cfg(feature = "compression")]
#[tokio::test]
async fn test_set_compression() {
    use product_os_server::Compression;
    
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    let compression = Compression {
        enable: true,
        gzip: true,
        deflate: true,
        brotli: false,
    };
    
    server.set_compression(Some(compression));
    // Compression setting should work
}

#[cfg(feature = "controller")]
#[tokio::test]
async fn test_controller_operations() {
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    // Test that controller can be set (None is valid)
    server.set_controller(None);
    // Controller setting should work
}

/// Test that POST handler can be added
#[tokio::test]
async fn test_add_post() {
    use product_os_server::{StatusCode, Response, Body};
    
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    async fn post_handler() -> Result<Response<Body>, StatusCode> {
        Ok(Response::new(Body::empty()))
    }
    
    server.add_post("/api/test", post_handler);
    // POST route addition should succeed
}

/// Test that custom method handlers can be added
#[tokio::test]
async fn test_add_handler_with_method() {
    use product_os_server::{StatusCode, Response, Method, Body};
    
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    async fn put_handler() -> Result<Response<Body>, StatusCode> {
        Ok(Response::new(Body::empty()))
    }
    
    server.add_handler("/api/update", Method::PUT, put_handler);
    // Custom method handler addition should succeed
}

#[cfg(feature = "ws")]
#[tokio::test]
async fn test_add_ws_handler() {
    use product_os_server::{StatusCode, Response, Body};
    
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    async fn ws_handler() -> Result<Response<Body>, StatusCode> {
        Ok(Response::new(Body::empty()))
    }
    
    server.add_ws_handler("/ws", ws_handler);
    // WebSocket handler addition should succeed
}

#[cfg(feature = "sse")]
#[tokio::test]
async fn test_add_sse_handler() {
    use product_os_server::{StatusCode, Response, Body};
    
    let config = ServerConfig::new();
    let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
    
    async fn sse_handler() -> Result<Response<Body>, StatusCode> {
        Ok(Response::new(Body::empty()))
    }
    
    server.add_sse_handler("/events", sse_handler);
    // SSE handler addition should succeed
}

/// Test re-exported types are accessible
#[test]
fn test_reexported_types() {
    use product_os_server::{
        StatusCode, Method
    };
    
    let _status = StatusCode::OK;
    let _method = Method::GET;
    // Re-exported types should be accessible
}