mod criterion;
mod expression;
mod http;
mod operation;
mod report;
mod run;
mod select;
pub mod testing;
#[cfg(feature = "reqwest")]
mod client;
pub use criterion::CriterionError;
pub use expression::ExpressionError;
pub use http::{
AsyncHttpClient, ClientError, HttpClient, HttpRequest, HttpResponse, SendFuture, SleepFuture,
};
pub use report::{
CriterionOutcome, ExecutionError, ExecutionReport, Outcome, Performed, StepRecord,
};
pub use run::{Options, Progress, Run};
pub use select::SelectError;
#[cfg(feature = "reqwest")]
pub use client::Client;
use roas_arazzo::v1_1::Description;
pub fn execute<C: HttpClient + ?Sized>(
description: &Description,
options: &Options,
client: &mut C,
) -> Result<ExecutionReport, ExecutionError> {
let mut run = Run::start(description, options)?;
loop {
match run.advance()? {
Progress::Send(request) => {
let response = client.send(&request).map_err(ExecutionError::from)?;
run.supply(response)?;
}
Progress::Wait(duration) => std::thread::sleep(duration),
Progress::Done(report) => return Ok(*report),
}
}
}
pub async fn execute_async<C: AsyncHttpClient + ?Sized>(
description: &Description,
options: &Options,
client: &mut C,
) -> Result<ExecutionReport, ExecutionError> {
let mut run = Run::start(description, options)?;
loop {
match run.advance()? {
Progress::Send(request) => {
let response = client.send(&request).await.map_err(ExecutionError::from)?;
run.supply(response)?;
}
Progress::Wait(duration) => client.sleep(duration).await,
Progress::Done(report) => return Ok(*report),
}
}
}
#[cfg(feature = "v1_0")]
pub fn execute_v1_0<C: HttpClient + ?Sized>(
description: &roas_arazzo::v1_0::Description,
options: &Options,
client: &mut C,
) -> Result<ExecutionReport, ExecutionError> {
execute(&Description::from(description.clone()), options, client)
}