#[cfg(test)]
mod tests {
use serde::{Deserialize, Serialize};
use serverless_fn::{ServerlessError, serverless};
#[derive(Serialize, Deserialize, Debug)]
pub struct Post {
pub id: u64,
pub title: String,
pub content: String,
}
#[serverless]
pub async fn test_read_posts(
how_many: usize,
query: String,
) -> Result<Vec<Post>, ServerlessError> {
let posts = (0..how_many)
.map(|i| Post {
id: i as u64,
title: format!("{query} {}", i),
content: format!("Content of post {}", i),
})
.collect();
Ok(posts)
}
#[tokio::test]
async fn test_serverless_function() {
let posts = test_read_posts(2, "test".to_string()).await.unwrap();
assert_eq!(posts.len(), 2);
assert_eq!(posts[0].title, "test 0");
assert_eq!(posts[1].title, "test 1");
}
}