diff --git a/axumtest/src/cases/mod.rs b/axumtest/src/cases/mod.rs index 5e19bb1..f369855 100644 --- a/axumtest/src/cases/mod.rs +++ b/axumtest/src/cases/mod.rs @@ -7,13 +7,12 @@ use axum::middleware; use axum::routing::get; use axum::Router; use futures::stream::TryStreamExt; -use futures::StreamExt; use mongodb::bson::doc; use mongodb::bson::Document; use mongodb::options::FindOptions; -use tokio::task::JoinHandle; use crate::auth; +use crate::entities::Case; use crate::State; /// Build the routes for the cases resource. @@ -35,28 +34,34 @@ pub fn router(state: Arc, ci_usr: String, ci_pwd: String, ci_role: String } async fn all_cases_on_collection(Path(collection): Path, state: Arc) -> String { - let collection = Arc::new(state.db.collection::(&collection)); - let options = FindOptions::builder() - .projection(doc! { "caseID": 1 }) - .build(); - let mut cursor = collection.find(None, options).await.unwrap(); - let mut calls = Vec::new(); + let collection = state.db.collection::(&collection); + let mut cursor = collection.find(None, None).await.unwrap(); + // let options = FindOptions::builder() + // .projection(doc! { "caseID": 1 }) + // .build(); + // let mut cursor = collection.find(None, options).await.unwrap(); + // let mut calls = Vec::new(); - while let Some(record) = cursor.try_next().await.unwrap() { - let name = record.get_str("caseID").unwrap(); - let filter = doc! { "caseID": name }; - let task_collection = Arc::clone(&collection); - let task = tokio::task::spawn(async move { - let record = task_collection.find_one(filter, None).await.unwrap(); - record - }); - - calls.push(task); - } + // while let Some(record) = cursor.try_next().await.unwrap() { + // let name = record.get_str("caseID").unwrap(); + // let filter = doc! { "caseID": name }; + // tracing::debug!(name, "filter: {}", filter); + // let task_collection = Arc::clone(&collection); + // let task = tokio::task::spawn(async move { + // let record = task_collection.find_one(filter, None).await.unwrap(); + // record + // }); - for handle in calls { - let record = handle.await; - tracing::debug!("Case: {:?}", record); + // calls.push(task); + // } + + // tracing::debug!("Awaiting data..."); + // for handle in calls { + // let record = handle.await; + // tracing::debug!("Case: {:?}", record.unwrap()); + // } + while let Some(record) = cursor.try_next().await.unwrap() { + tracing::debug!(?record); } format!("Cases!") diff --git a/axumtest/src/entities/mod.rs b/axumtest/src/entities/mod.rs index eedce79..46db020 100644 --- a/axumtest/src/entities/mod.rs +++ b/axumtest/src/entities/mod.rs @@ -1,5 +1,7 @@ //! Entities used in the system. +use std::collections::HashMap; + use clap::Parser; use mongodb::Database; @@ -46,3 +48,34 @@ impl ErrorResponse { } } } + +#[derive(Debug, serde::Serialize, serde::Deserialize)] +pub struct Comparison { + absolute_tolerance: f64, + relative_tolerance: f64, +} + +#[derive(Debug, serde::Serialize, serde::Deserialize)] +pub struct Compare { + file_to_test: String, + entries_to_compare: HashMap, +} + +#[derive(Debug, serde::Serialize, serde::Deserialize)] +pub struct Case { + #[serde(default)] + files: Vec, + timeout: Option, + #[serde(default)] + run: Vec, + #[serde(default)] + parallel: Vec, + procs: Option, + + #[serde(default)] + tags: Vec, + version: Option, + + #[serde(default)] + compare: HashMap, +}