use liminal_sdk::{
ChannelHandle, ConnectionPoolConfig, EmbeddedConfig, PressureResponse, RemoteConfig,
SchemaMetadata, SchemaValidate, SdkConfig, SdkError, build_channel_handle,
};
use serde::Serialize;
#[derive(Serialize)]
struct SwitchMessage {
id: u64,
}
impl SchemaValidate for SwitchMessage {
fn schema_metadata() -> SchemaMetadata {
SchemaMetadata::new("switch.message", "1", br#"{"type":"object"}"#.as_slice())
}
}
#[test]
fn switching_between_embedded_and_remote_changes_only_config() -> Result<(), SdkError> {
let embedded = SdkConfig::embedded(EmbeddedConfig::new("events", "conversation"));
let remote = SdkConfig::remote(RemoteConfig::new(
"127.0.0.1:9000",
"events",
"conversation",
ConnectionPoolConfig::new(1, 10, 16),
)?);
let embedded_result = publish_with_same_application_code(&build_channel_handle(&embedded)?);
assert!(
matches!(embedded_result, Err(SdkError::Unwired { .. })),
"the default embedded backend must refuse, got {embedded_result:?}"
);
let remote_result = publish_with_same_application_code(&build_channel_handle(&remote)?);
assert!(
matches!(remote_result, Err(SdkError::NotConnected { .. })),
"an unconnected remote config must refuse the publish, got {remote_result:?}"
);
Ok(())
}
fn publish_with_same_application_code<H>(handle: &H) -> Result<PressureResponse, SdkError>
where
H: ChannelHandle,
{
handle.publish(SwitchMessage { id: 1 })
}