// file: crates/ksp-store-lib/unit_tests/store.rs // version: 2 fn poll_ready(future: impl std::future::Future) -> 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!("pre.003 Store contract future unexpectedly became pending before any I/O exists"), }; } fn valid_store_settings() -> crate::StoreSettings { let postgres = crate::PostgresStoreSettings::new( "postgresql://secret-user:secret-password@db.internal/ksp", crate::PostgresPoolSettings::default(), crate::PostgresTlsMode::VerifyFull, crate::PostgresBootstrapSettings::default(), ); return crate::StoreSettings::with_default_shutdown(crate::StoreBackendSettings::Postgres(postgres)); } #[test] fn invalid_settings_are_rejected_before_backend_dispatch() { let postgres = crate::PostgresStoreSettings::new( std::string::String::new(), crate::PostgresPoolSettings::default(), crate::PostgresTlsMode::Disabled, crate::PostgresBootstrapSettings::default(), ); let settings = crate::StoreSettings::with_default_shutdown(crate::StoreBackendSettings::Postgres(postgres)); let result = poll_ready(crate::Store::open(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_dispatch_does_not_fake_readiness_before_connection_materialization() { let result = poll_ready(crate::Store::open(valid_store_settings())); let error = result.err(); assert_eq!(error.map(|value| return value.code()), std::option::Option::Some(crate::ERROR_CODE_BACKEND_OPEN_FAILED)); return; } #[cfg(not(feature = "postgres"))] #[test] fn known_postgres_without_feature_is_rejected_before_io() { let result = poll_ready(crate::Store::open(valid_store_settings())); let error = result.err(); assert_eq!(error.map(|value| return value.code()), std::option::Option::Some(crate::ERROR_CODE_BACKEND_NOT_COMPILED)); return; }