Files
khadhroony-solana-project/crates/ksp-store-lib/unit_tests/store.rs
2026-08-29 19:33:43 +02:00

58 lines
2.3 KiB
Rust

// file: crates/ksp-store-lib/unit_tests/store.rs
// version: 4
fn poll_ready<T>(future: impl std::future::Future<Output = T>) -> T {
let mut future = std::boxed::Box::pin(future);
let waker = std::task::Waker::noop();
let mut context = std::task::Context::from_waker(waker);
return match std::future::Future::poll(future.as_mut(), &mut context) {
std::task::Poll::Ready(value) => value,
std::task::Poll::Pending => panic!("Store pre-I/O rejection unexpectedly became pending"),
};
}
fn valid_network() -> crate::RawNetworkId {
return match crate::RawNetworkId::new("devnet") {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => panic!("valid test network rejected: {error:?}"),
};
}
fn store_settings(connection_uri: &str) -> crate::StoreSettings {
let postgres = crate::PostgresStoreSettings::new(
connection_uri,
crate::PostgresPoolSettings::default(),
crate::PostgresTlsMode::Disabled,
crate::PostgresBootstrapSettings::default(),
);
return crate::StoreSettings::with_default_shutdown(valid_network(), crate::StoreBackendSettings::Postgres(postgres));
}
#[test]
fn invalid_settings_are_rejected_before_backend_dispatch() {
let result = poll_ready(crate::Store::open(store_settings("")));
let error = result.err();
assert_eq!(error.map(|value| return value.code()), std::option::Option::Some(crate::ERROR_CODE_SETTINGS_INVALID));
return;
}
#[cfg(feature = "postgres")]
#[test]
fn compiled_postgres_rejects_malformed_physical_configuration_before_io() {
let secret_canary = "not-a-postgresql-uri-secret-canary";
let result = poll_ready(crate::Store::open(store_settings(secret_canary)));
let error = result.err();
assert_eq!(error.as_ref().map(|value| return value.code()), std::option::Option::Some(crate::ERROR_CODE_POSTGRES_CONFIG_INVALID));
assert!(!format!("{error:?}").contains(secret_canary));
return;
}
#[cfg(not(feature = "postgres"))]
#[test]
fn known_postgres_without_feature_is_rejected_before_io() {
let result = poll_ready(crate::Store::open(store_settings("postgresql://operator-supplied-sensitive-value@localhost/ksp")));
let error = result.err();
assert_eq!(error.map(|value| return value.code()), std::option::Option::Some(crate::ERROR_CODE_BACKEND_NOT_COMPILED));
return;
}