use std::error::Error; use async_once_cell::OnceCell; use genius_core_client::{ client::{Client, Protocol}, types::error::HstpError, CollisionStrategy, }; static CELL: OnceCell> = async_once_cell::OnceCell::new(); async fn upsert_docs() -> Result { let token = std::env::var("GENIUS_JWT").map_err(HstpError::from_error)?; let db_url = std::env::var("GENIUS_DB_URL").map_err(HstpError::from_error)?; let port = std::env::var("GENIUS_DB_PORT").map_err(HstpError::from_error)?; let mut client = Client::new_with_oauth2_token(Protocol::HTTPS, db_url, port, token.clone(), None).await?; client .upsert_hsml_json( "./tests/data/schemas.json", CollisionStrategy::ForceOverwrite, ) .await?; client .upsert_hsml_json( "./tests/data/gps_vec_space.json", CollisionStrategy::ForceOverwrite, ) .await?; client .upsert_hsml_json( "./tests/data/gps_schemas.json", CollisionStrategy::ForceOverwrite, ) .await?; client .upsert_hsml_json("./tests/data/data0.json", CollisionStrategy::ForceOverwrite) .await?; client .upsert_hsml_json("./tests/data/data1.json", CollisionStrategy::ForceOverwrite) .await?; client .upsert_hsml_json("./tests/data/data2.json", CollisionStrategy::ForceOverwrite) .await?; client .upsert_hsml_json("./tests/data/data3.json", CollisionStrategy::ForceOverwrite) .await?; client .upsert_hsml_json("./tests/data/data4.json", CollisionStrategy::ForceOverwrite) .await?; client .upsert_hsml_json("./tests/data/data5.json", CollisionStrategy::ForceOverwrite) .await?; client .upsert_hsml_json("./tests/data/data6.json", CollisionStrategy::ForceOverwrite) .await?; client .upsert_hsml_json("./tests/data/data7.json", CollisionStrategy::ForceOverwrite) .await?; client .upsert_hsml_json( "./tests/data/vectorizer_test_schema.json", CollisionStrategy::ForceOverwrite, ) .await?; client .upsert_hsml_json( "./tests/data/vectorizer_test_obj.json", CollisionStrategy::ForceOverwrite, ) .await?; Ok(token) } #[allow(dead_code)] pub async fn prepare_test() -> Result> { let token = CELL.get_or_init(upsert_docs()).await.clone()?; let db_url = std::env::var("GENIUS_DB_URL").map_err(HstpError::from_error)?; let port = std::env::var("GENIUS_DB_PORT").map_err(HstpError::from_error)?; let client = Client::new_with_oauth2_token(Protocol::HTTPS, db_url, port, token.clone(), None).await?; Ok(client) }