#![cfg(feature = "executor_tokio")]
use product_os_server::{ProductOSServer, ProductOSServerError};
use product_os_async_executor::TokioExecutor;
use product_os_server::ServerConfig;
#[tokio::test]
async fn test_new_with_config() {
let config = ServerConfig::new();
let _server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
}
#[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);
}
#[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);
}
#[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();
}
#[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);
}
#[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);
}
#[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);
}
#[tokio::test]
async fn test_add_middleware() {
let config = ServerConfig::new();
let _server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
}
#[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);
}
#[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);
}
#[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);
}
#[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"));
}
#[test]
fn test_error_type() {
let _error = ProductOSServerError::GenericError("test".to_string());
}
#[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));
}
#[cfg(feature = "controller")]
#[tokio::test]
async fn test_controller_operations() {
let config = ServerConfig::new();
let mut server: ProductOSServer<(), TokioExecutor, _> = ProductOSServer::new_with_config(config);
server.set_controller(None);
}
#[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);
}
#[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);
}
#[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);
}
#[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);
}
#[test]
fn test_reexported_types() {
use product_os_server::{
StatusCode, Method
};
let _status = StatusCode::OK;
let _method = Method::GET;
}