Files
khadhroony-solana-project/crates/ksp-store-postgres-lib/unit_tests/health.rs
2026-08-29 21:40:57 +02:00

43 lines
2.0 KiB
Rust

// file: crates/ksp-store-postgres-lib/unit_tests/health.rs
// version: 1
#[test]
fn pool_status_projection_is_bounded_and_contains_no_physical_handle() {
let status = deadpool_postgres::Status { max_size: 8, size: 3, available: 2, waiting: 1 };
let snapshot = crate::runtime_snapshot_from_status(status);
assert_eq!(snapshot.pool_capacity(), 8);
assert_eq!(snapshot.pool_size(), 3);
assert_eq!(snapshot.pool_available(), 2);
assert_eq!(snapshot.pool_waiting(), 1);
return;
}
#[test]
fn health_snapshot_distinguishes_ready_and_safe_failure_without_server_text() {
let status = deadpool_postgres::Status { max_size: 8, size: 1, available: 1, waiting: 0 };
let runtime = crate::runtime_snapshot_from_status(status);
let ready = crate::PostgresBackendHealthSnapshot::ready(runtime, 0, 0);
assert!(ready.is_ready());
assert_eq!(ready.migration_version(), std::option::Option::Some(0));
assert_eq!(ready.error_kind(), std::option::Option::None);
let failed =
crate::PostgresBackendHealthSnapshot::not_ready(ready.runtime().clone(), std::option::Option::None, 0, crate::PostgresBackendErrorKind::HealthFailed);
assert!(!failed.is_ready());
assert_eq!(failed.error_kind(), std::option::Option::Some(crate::PostgresBackendErrorKind::HealthFailed));
let rendered = format!("{failed:?}");
for forbidden in ["postgresql://", "SELECT ", "ksp_store_schema_migrations", "password", "server error"] {
assert!(!rendered.contains(forbidden), "unsafe backend health material detected: {forbidden}");
}
return;
}
#[test]
fn migration_health_helpers_keep_unknown_and_pending_counts_safe() {
assert_eq!(super::nonnegative_version(-1), std::option::Option::None);
assert_eq!(super::nonnegative_version(0), std::option::Option::Some(0));
assert_eq!(super::pending_migration_count(-1, 0), 1);
assert_eq!(super::pending_migration_count(0, 0), 0);
assert_eq!(super::pending_migration_count(1, 0), 0);
return;
}