Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/rustapi-core/src/app/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl RustApi {
/// The primary way to build a RustAPI application.
///
/// Collects all routes decorated with `#[rustapi_rs::get]`, `#[rustapi_rs::post]`, etc.
/// at link time via `linkme` and registers them automatically ├óÔé¼ÔÇØ no manual `.route()`
/// at link time via `linkme` and registers them automatically no manual `.route()`
/// or `.mount_route()` calls needed. This is baked into the core and requires no
/// feature flags.
///
Expand Down Expand Up @@ -288,7 +288,7 @@ impl RustApi {
/// ```rust,ignore
/// RustApi::new()
/// .on_start(|| async {
/// println!("─ş┼©┼íÔé¼ Server starting...");
/// println!("Server starting...");
/// // e.g. run DB migrations, warm caches
/// })
/// .run("127.0.0.1:8080")
Expand All @@ -315,7 +315,7 @@ impl RustApi {
/// ```rust,ignore
/// RustApi::new()
/// .on_shutdown(|| async {
/// println!("─ş┼©ÔÇİÔÇ╣ Server shutting down...");
/// println!("Server shutting down...");
/// // e.g. flush logs, close DB connections
/// })
/// .run_with_shutdown("127.0.0.1:8080", ctrl_c())
Expand Down
2 changes: 1 addition & 1 deletion crates/rustapi-core/src/app/production.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Configuration for RustAPI's built-in production baseline preset.
/// Configuration for RustAPI's built-in production baseline preset.
///
/// This preset bundles together the most common foundation pieces for a
/// production HTTP service:
Expand Down
2 changes: 1 addition & 1 deletion crates/rustapi-core/src/app/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl RustApi {
// For now we assume one handler per path or we simply allow overwriting for this MVP step
// (matchit router doesn't allow easy merging/updating existing entries without rebuilding)
//
// TOOD: Enhance Router to support method merging
// TODO: Enhance Router to support method merging

let path = if !path.starts_with('/') {
format!("/{}", path)
Expand Down
62 changes: 62 additions & 0 deletions crates/rustapi-core/src/app/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,65 @@ fn test_rustapi_nest_includes_routes_in_openapi_spec() {
"Should have 'item_id' path parameter"
);
}

#[test]
fn apply_health_endpoints_registers_default_paths() {
let mut app = RustApi::new().health_endpoints();
app.apply_health_endpoints();
let router = app.into_router();
let routes = router.registered_routes();
assert!(routes.contains_key("/health"));
assert!(routes.contains_key("/ready"));
assert!(routes.contains_key("/live"));
}

#[test]
fn apply_status_page_registers_status_route() {
let mut app = RustApi::new().status_page();
app.apply_status_page();
let router = app.into_router();
assert!(router.registered_routes().contains_key("/status"));
}

#[test]
fn print_hot_reload_banner_is_noop_when_disabled() {
let app = RustApi::new();
app.print_hot_reload_banner("127.0.0.1:8080");
}

#[test]
fn print_hot_reload_banner_logs_when_enabled() {
let app = RustApi::new().hot_reload(true);
app.print_hot_reload_banner("127.0.0.1:8080");
}

#[tokio::test]
async fn on_start_hooks_execute_in_registration_order() {
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

let order = Arc::new(AtomicUsize::new(0));
let mut app = RustApi::new()
.on_start({
let order = order.clone();
move || {
let order = order.clone();
async move {
assert_eq!(order.fetch_add(1, Ordering::SeqCst), 0);
}
}
})
.on_start({
let order = order.clone();
move || {
let order = order.clone();
async move {
assert_eq!(order.fetch_add(1, Ordering::SeqCst), 1);
}
}
});

for hook in std::mem::take(&mut app.lifecycle_hooks.on_start) {
hook().await;
}
}
2 changes: 1 addition & 1 deletion crates/rustapi-core/src/app/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::events::LifecycleHooks;
use crate::events::LifecycleHooks;
use crate::interceptor::InterceptorChain;
use crate::middleware::LayerStack;
use crate::router::Router;
Expand Down
Loading
Loading