tablo-core 0.10.0

The core toolkit types for Tablo, a server-rendered admin toolkit on Topcoat and Toasty.
Documentation
use super::*;

#[test]
fn unavailable_maps_infra_failures_to_an_opaque_error() {
    // Driver text is for the logs, never the error page.
    let err = unavailable("secret driver gunk: no such table");
    let rendered = err.to_string();
    assert!(
        rendered.contains(DATABASE_UNAVAILABLE),
        "the opaque message must survive, got {rendered}"
    );
    assert!(
        !rendered.contains("gunk"),
        "driver text must not leak, got {rendered}"
    );
    assert!(TabloError::is_infrastructure(&err));
}

/// A record hook that fails at the driver is an infra failure, so
/// the write surfaces the opaque mapping — the property
/// `unavailable_maps_infra_failures_to_an_opaque_error` pins, reached
/// through the driver seam.
#[test]
fn driver_failure_maps_driver_errors_to_an_opaque_error() {
    let err = driver_failure(
        toasty::Error::from_args(format_args!("secret driver gunk: no such table")),
        DATABASE_UNAVAILABLE,
    );
    let rendered = err.to_string();
    assert!(
        rendered.contains(DATABASE_UNAVAILABLE),
        "the opaque message must survive, got {rendered}"
    );
    assert!(
        !rendered.contains("gunk"),
        "driver text must not leak, got {rendered}"
    );
    assert!(TabloError::is_infrastructure(&err));
}

/// An app-authored error is not the driver's,
/// so it keeps its own mapping — a guard's 404 stays a 404 rather than
/// becoming the opaque 500.
#[test]
fn driver_failure_keeps_an_app_error_intact() {
    let guard: topcoat::Error = topcoat::router::error::not_found().into();
    let err = driver_failure(guard, DATABASE_UNAVAILABLE);
    assert!(
        err.is::<topcoat::router::error::NotFoundError>(),
        "an app-authored error must keep its own mapping"
    );
    assert!(!TabloError::is_infrastructure(&err));
}

/// A serialization failure answers like any outage, and is told apart so its transaction can
/// run again.
#[test]
fn driver_failure_marks_a_serialization_failure_as_a_conflict() {
    let err = driver_failure(
        toasty::Error::serialization_failure("could not serialize access"),
        DATABASE_UNAVAILABLE,
    );
    assert!(TabloError::is_conflict(&err));
    assert!(TabloError::is_infrastructure(&err));
    assert!(!err.to_string().contains("serialize"));
}