use axum::{Router, routing::get};
use rullst::{error_console::catch_panic_middleware, testing::TestApp};
async fn panic_handler() {
panic!("Opa! Algo deu errado no Rullst!");
}
fn build_panic_router() -> Router {
Router::new()
.route("/panic", get(panic_handler))
.layer(axum::middleware::from_fn(catch_panic_middleware))
}
#[tokio::test]
async fn test_error_console_catches_panic_and_renders_html() {
unsafe {
std::env::set_var("RUST_BACKTRACE", "1");
}
let app = TestApp::new(build_panic_router());
let response = app.get("/panic").await;
response.assert_status(500);
response
.assert_header("content-type", "text/html; charset=utf-8")
.assert_see("Rullst Self-Healing Console")
.assert_see("Opa! Algo deu errado no Rullst!")
.assert_see("Source Code Snippet");
response.assert_see("Stack Trace");
}