Skip to content

Commit eaa7192

Browse files
committed
fix(#201): satisfy goal AC1 — split oversize modules, fix encoding, add run tests
1 parent 322d5f4 commit eaa7192

12 files changed

Lines changed: 3380 additions & 3323 deletions

File tree

crates/rustapi-core/src/app/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl RustApi {
4747
/// The primary way to build a RustAPI application.
4848
///
4949
/// Collects all routes decorated with `#[rustapi_rs::get]`, `#[rustapi_rs::post]`, etc.
50-
/// at link time via `linkme` and registers them automatically ├óÔé¼ÔÇØ no manual `.route()`
50+
/// at link time via `linkme` and registers them automatically no manual `.route()`
5151
/// or `.mount_route()` calls needed. This is baked into the core and requires no
5252
/// feature flags.
5353
///
@@ -288,7 +288,7 @@ impl RustApi {
288288
/// ```rust,ignore
289289
/// RustApi::new()
290290
/// .on_start(|| async {
291-
/// println!("─ş┼©┼íÔé¼ Server starting...");
291+
/// println!("Server starting...");
292292
/// // e.g. run DB migrations, warm caches
293293
/// })
294294
/// .run("127.0.0.1:8080")
@@ -315,7 +315,7 @@ impl RustApi {
315315
/// ```rust,ignore
316316
/// RustApi::new()
317317
/// .on_shutdown(|| async {
318-
/// println!("─ş┼©ÔÇİÔÇ╣ Server shutting down...");
318+
/// println!("Server shutting down...");
319319
/// // e.g. flush logs, close DB connections
320320
/// })
321321
/// .run_with_shutdown("127.0.0.1:8080", ctrl_c())

crates/rustapi-core/src/app/production.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Configuration for RustAPI's built-in production baseline preset.
1+
/// Configuration for RustAPI's built-in production baseline preset.
22
///
33
/// This preset bundles together the most common foundation pieces for a
44
/// production HTTP service:

crates/rustapi-core/src/app/routing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl RustApi {
173173
// For now we assume one handler per path or we simply allow overwriting for this MVP step
174174
// (matchit router doesn't allow easy merging/updating existing entries without rebuilding)
175175
//
176-
// TOOD: Enhance Router to support method merging
176+
// TODO: Enhance Router to support method merging
177177

178178
let path = if !path.starts_with('/') {
179179
format!("/{}", path)

crates/rustapi-core/src/app/tests.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,3 +778,65 @@ fn test_rustapi_nest_includes_routes_in_openapi_spec() {
778778
"Should have 'item_id' path parameter"
779779
);
780780
}
781+
782+
#[test]
783+
fn apply_health_endpoints_registers_default_paths() {
784+
let mut app = RustApi::new().health_endpoints();
785+
app.apply_health_endpoints();
786+
let router = app.into_router();
787+
let routes = router.registered_routes();
788+
assert!(routes.contains_key("/health"));
789+
assert!(routes.contains_key("/ready"));
790+
assert!(routes.contains_key("/live"));
791+
}
792+
793+
#[test]
794+
fn apply_status_page_registers_status_route() {
795+
let mut app = RustApi::new().status_page();
796+
app.apply_status_page();
797+
let router = app.into_router();
798+
assert!(router.registered_routes().contains_key("/status"));
799+
}
800+
801+
#[test]
802+
fn print_hot_reload_banner_is_noop_when_disabled() {
803+
let app = RustApi::new();
804+
app.print_hot_reload_banner("127.0.0.1:8080");
805+
}
806+
807+
#[test]
808+
fn print_hot_reload_banner_logs_when_enabled() {
809+
let app = RustApi::new().hot_reload(true);
810+
app.print_hot_reload_banner("127.0.0.1:8080");
811+
}
812+
813+
#[tokio::test]
814+
async fn on_start_hooks_execute_in_registration_order() {
815+
use std::sync::atomic::{AtomicUsize, Ordering};
816+
use std::sync::Arc;
817+
818+
let order = Arc::new(AtomicUsize::new(0));
819+
let mut app = RustApi::new()
820+
.on_start({
821+
let order = order.clone();
822+
move || {
823+
let order = order.clone();
824+
async move {
825+
assert_eq!(order.fetch_add(1, Ordering::SeqCst), 0);
826+
}
827+
}
828+
})
829+
.on_start({
830+
let order = order.clone();
831+
move || {
832+
let order = order.clone();
833+
async move {
834+
assert_eq!(order.fetch_add(1, Ordering::SeqCst), 1);
835+
}
836+
}
837+
});
838+
839+
for hook in std::mem::take(&mut app.lifecycle_hooks.on_start) {
840+
hook().await;
841+
}
842+
}

crates/rustapi-core/src/app/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::events::LifecycleHooks;
1+
use crate::events::LifecycleHooks;
22
use crate::interceptor::InterceptorChain;
33
use crate::middleware::LayerStack;
44
use crate::router::Router;

0 commit comments

Comments
 (0)