mod common;
use ankurah::error::RetrievalError;
use ankurah::{policy::DEFAULT_CONTEXT as c, EntityId, Node, PermissiveAgent};
use anyhow::Result;
use std::sync::Arc;
#[tokio::test]
async fn postgres_get_state_returns_entity_not_found() -> Result<()> {
let (_container, storage_engine) = common::create_postgres_container().await?;
let node = Node::new_durable(Arc::new(storage_engine), PermissiveAgent::new());
node.system.create().await?;
let context = node.context(c)?;
let collection = context.collection(&"album".into()).await?;
let non_existent_id = EntityId::new();
let result = collection.get_state(non_existent_id).await;
match result {
Err(RetrievalError::EntityNotFound(id)) => {
assert_eq!(id, non_existent_id, "EntityNotFound should contain the requested ID");
}
Err(RetrievalError::StorageError(e)) => {
panic!(
"get_state returned StorageError instead of EntityNotFound: {}. \
This indicates the postgres storage is not properly handling the \
'query returned an unexpected number of rows' error from query_one.",
e
);
}
Err(e) => {
panic!("get_state returned unexpected error: {:?}", e);
}
Ok(_) => {
panic!("get_state returned Ok for non-existent entity - this should not happen");
}
}
Ok(())
}