#![allow(dead_code)]
use std::time::SystemTime;
use futures::executor::block_on;
use lambda_http::http::Request as Builder;
use lambda_http::{Body, Request, Response};
use turul_ai_catalog::parse::parse;
use turul_ai_catalog_lambda::ServedCatalog;
use turul_ai_catalog_storage::{CatalogId, InMemoryCatalogStore, WriterId, import};
pub fn request(method: &str, uri: &str) -> Request {
Builder::builder()
.method(method)
.uri(uri)
.body(Body::Empty)
.expect("request builds")
}
pub fn body_bytes(response: &Response<Body>) -> Vec<u8> {
match response.body() {
Body::Empty => Vec::new(),
Body::Text(s) => s.as_bytes().to_vec(),
Body::Binary(b) => b.clone(),
#[allow(unreachable_patterns)]
_ => panic!("unexpected body variant"),
}
}
pub fn fixture_writer() -> WriterId {
WriterId::new("fixture").expect("valid writer id")
}
pub fn catalog_id() -> CatalogId {
CatalogId::new("test").expect("valid catalog id")
}
pub fn store_with(document: &str) -> InMemoryCatalogStore {
let store = InMemoryCatalogStore::new();
let parsed = parse(document.as_bytes()).expect("fixture parses");
block_on(import(&store, &catalog_id(), &parsed, &fixture_writer())).expect("fixture imports");
store
}
pub fn served_from(document: &str) -> ServedCatalog {
match block_on(ServedCatalog::assemble(
&store_with(document),
&catalog_id(),
SystemTime::now(),
)) {
Ok(s) => s,
Err(e) => panic!("fixture must assemble: {e}"),
}
}