generate `httpmock`-based testing code (#437)
This commit is contained in:
parent
a9e76608ca
commit
7da8db8544
|
@ -17,6 +17,8 @@ https://github.com/oxidecomputer/progenitor/compare/v0.2.0\...HEAD[Full list of
|
|||
|
||||
* Add support for header parameters (#210)
|
||||
* Add support for YAML input (#227)
|
||||
* Add generation for `clap`-based CLIs
|
||||
* Add generation for strongly-typed mocks with `httpmock`
|
||||
|
||||
== 0.2.0 (released 2022-09-11)
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ readme = "../README.md"
|
|||
|
||||
[dependencies]
|
||||
heck = "0.4.1"
|
||||
http = "0.2.9"
|
||||
getopts = "0.2"
|
||||
indexmap = "1.9"
|
||||
openapiv3 = "1.0.0"
|
||||
|
|
|
@ -42,6 +42,7 @@ impl Generator {
|
|||
space_out_items(content)
|
||||
}
|
||||
|
||||
/// Generate a `clap`-based CLI.
|
||||
pub fn cli(
|
||||
&mut self,
|
||||
spec: &OpenAPI,
|
||||
|
|
|
@ -0,0 +1,344 @@
|
|||
// Copyright 2023 Oxide Computer Company
|
||||
|
||||
//! Generation of mocking extensions for `httpmock`
|
||||
|
||||
use openapiv3::OpenAPI;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote, ToTokens};
|
||||
|
||||
use crate::{
|
||||
method::{
|
||||
HttpMethod, OperationParameter, OperationParameterKind,
|
||||
OperationParameterType, OperationResponse, OperationResponseStatus,
|
||||
},
|
||||
to_schema::ToSchema,
|
||||
util::{sanitize, Case},
|
||||
validate_openapi, Generator, Result,
|
||||
};
|
||||
|
||||
struct MockOp {
|
||||
when: TokenStream,
|
||||
when_impl: TokenStream,
|
||||
then: TokenStream,
|
||||
then_impl: TokenStream,
|
||||
}
|
||||
|
||||
impl Generator {
|
||||
/// Generate a strongly-typed mocking extension to the `httpmock` crate.
|
||||
pub fn httpmock(
|
||||
&mut self,
|
||||
spec: &OpenAPI,
|
||||
crate_name: &str,
|
||||
) -> Result<TokenStream> {
|
||||
validate_openapi(spec)?;
|
||||
|
||||
// Convert our components dictionary to schemars
|
||||
let schemas = spec.components.iter().flat_map(|components| {
|
||||
components.schemas.iter().map(|(name, ref_or_schema)| {
|
||||
(name.clone(), ref_or_schema.to_schema())
|
||||
})
|
||||
});
|
||||
|
||||
self.type_space.add_ref_types(schemas)?;
|
||||
|
||||
let raw_methods = spec
|
||||
.paths
|
||||
.iter()
|
||||
.flat_map(|(path, ref_or_item)| {
|
||||
// Exclude externally defined path items.
|
||||
let item = ref_or_item.as_item().unwrap();
|
||||
item.iter().map(move |(method, operation)| {
|
||||
(path.as_str(), method, operation, &item.parameters)
|
||||
})
|
||||
})
|
||||
.map(|(path, method, operation, path_parameters)| {
|
||||
self.process_operation(
|
||||
operation,
|
||||
&spec.components,
|
||||
path,
|
||||
method,
|
||||
path_parameters,
|
||||
)
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
let methods = raw_methods
|
||||
.iter()
|
||||
.map(|method| self.httpmock_method(method))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let op = raw_methods
|
||||
.iter()
|
||||
.map(|method| format_ident!("{}", &method.operation_id))
|
||||
.collect::<Vec<_>>();
|
||||
let when = methods.iter().map(|op| &op.when).collect::<Vec<_>>();
|
||||
let when_impl =
|
||||
methods.iter().map(|op| &op.when_impl).collect::<Vec<_>>();
|
||||
let then = methods.iter().map(|op| &op.then).collect::<Vec<_>>();
|
||||
let then_impl =
|
||||
methods.iter().map(|op| &op.then_impl).collect::<Vec<_>>();
|
||||
|
||||
let crate_ident = format_ident!("{}", crate_name);
|
||||
|
||||
let code = quote! {
|
||||
pub mod operations {
|
||||
|
||||
//! [`When`](httpmock::When) and [`Then`](httpmock::Then)
|
||||
//! wrappers for each operation. Each can be converted to
|
||||
//! its inner type with a call to `into_inner()`. This can
|
||||
//! be used to explicitly deviate from permitted values.
|
||||
|
||||
use #crate_ident::*;
|
||||
|
||||
#(
|
||||
pub struct #when(httpmock::When);
|
||||
#when_impl
|
||||
|
||||
pub struct #then(httpmock::Then);
|
||||
#then_impl
|
||||
)*
|
||||
}
|
||||
|
||||
/// An extension trait for [`MockServer`](httpmock::MockServer) that
|
||||
/// adds a method for each operation. These are the equivalent of
|
||||
/// type-checked [`mock()`](httpmock::MockServer::mock) calls.
|
||||
pub trait MockServerExt {
|
||||
#(
|
||||
fn #op<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::#when, operations::#then);
|
||||
)*
|
||||
}
|
||||
|
||||
impl MockServerExt for httpmock::MockServer {
|
||||
#(
|
||||
fn #op<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::#when, operations::#then)
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::#when::new(when),
|
||||
operations::#then::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
)*
|
||||
}
|
||||
};
|
||||
Ok(code)
|
||||
}
|
||||
|
||||
fn httpmock_method(
|
||||
&mut self,
|
||||
method: &crate::method::OperationMethod,
|
||||
) -> MockOp {
|
||||
let when_name =
|
||||
sanitize(&format!("{}-when", method.operation_id), Case::Pascal);
|
||||
let when = format_ident!("{}", when_name).to_token_stream();
|
||||
let then_name =
|
||||
sanitize(&format!("{}-then", method.operation_id), Case::Pascal);
|
||||
let then = format_ident!("{}", then_name).to_token_stream();
|
||||
|
||||
let http_method = match &method.method {
|
||||
HttpMethod::Get => quote! { httpmock::Method::GET },
|
||||
HttpMethod::Put => quote! { httpmock::Method::PUT },
|
||||
HttpMethod::Post => quote! { httpmock::Method::POST },
|
||||
HttpMethod::Delete => quote! { httpmock::Method::DELETE },
|
||||
HttpMethod::Options => quote! { httpmock::Method::OPTIONS },
|
||||
HttpMethod::Head => quote! { httpmock::Method::HEAD },
|
||||
HttpMethod::Patch => quote! { httpmock::Method::PATCH },
|
||||
HttpMethod::Trace => quote! { httpmock::Method::TRACE },
|
||||
};
|
||||
|
||||
let path_re = method.path.as_wildcard();
|
||||
|
||||
// Generate methods corresponding to each parameter so that callers
|
||||
// can specify a prescribed value for that parameter.
|
||||
let when_methods = method.params.iter().map(
|
||||
|OperationParameter {
|
||||
name, typ, kind, ..
|
||||
}| {
|
||||
let arg_type_name = match typ {
|
||||
OperationParameterType::Type(arg_type_id) => {
|
||||
let arg_type =
|
||||
self.type_space.get_type(arg_type_id).unwrap();
|
||||
let arg_details = arg_type.details();
|
||||
let arg_type_name = match &arg_details {
|
||||
typify::TypeDetails::Option(opt_id) => {
|
||||
let inner_type =
|
||||
self.type_space.get_type(opt_id).unwrap();
|
||||
inner_type.parameter_ident()
|
||||
}
|
||||
_ => arg_type.parameter_ident(),
|
||||
};
|
||||
arg_type_name
|
||||
}
|
||||
OperationParameterType::RawBody => quote! {
|
||||
serde_json::Value
|
||||
},
|
||||
};
|
||||
|
||||
let name_ident = format_ident!("{}", name);
|
||||
let handler = match kind {
|
||||
OperationParameterKind::Path => {
|
||||
let re_fmt = method.path.as_wildcard_param(name);
|
||||
quote! {
|
||||
let re = regex::Regex::new(
|
||||
&format!(#re_fmt, value.to_string())
|
||||
).unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
}
|
||||
OperationParameterKind::Query(_) => quote! {
|
||||
Self(self.0.query_param(#name, value.to_string()))
|
||||
},
|
||||
OperationParameterKind::Header(_) => quote! { todo!() },
|
||||
OperationParameterKind::Body(_) => match typ {
|
||||
OperationParameterType::Type(_) => quote! {
|
||||
Self(self.0.json_body_obj(value))
|
||||
|
||||
},
|
||||
OperationParameterType::RawBody => quote! {
|
||||
Self(self.0.json_body(value))
|
||||
},
|
||||
},
|
||||
};
|
||||
quote! {
|
||||
pub fn #name_ident(self, value: #arg_type_name) -> Self {
|
||||
#handler
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let when_impl = quote! {
|
||||
impl #when {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(inner
|
||||
.method(#http_method)
|
||||
.path_matches(regex::Regex::new(#path_re).unwrap()))
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
#(#when_methods)*
|
||||
}
|
||||
};
|
||||
|
||||
// Methods for each discrete response. For specific status codes we use
|
||||
// the name of that code; for classes of codes we use the class name
|
||||
// and require a status code that must be within the prescribed range.
|
||||
let then_methods = method.responses.iter().map(
|
||||
|OperationResponse {
|
||||
status_code, typ, ..
|
||||
}| {
|
||||
let (value_param, value_use) = match typ {
|
||||
crate::method::OperationResponseType::Type(arg_type_id) => {
|
||||
let arg_type =
|
||||
self.type_space.get_type(arg_type_id).unwrap();
|
||||
let arg_type_ident = arg_type.parameter_ident();
|
||||
(
|
||||
quote! {
|
||||
value: #arg_type_ident,
|
||||
},
|
||||
quote! {
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value)
|
||||
},
|
||||
)
|
||||
}
|
||||
crate::method::OperationResponseType::None => {
|
||||
Default::default()
|
||||
}
|
||||
crate::method::OperationResponseType::Raw => (
|
||||
quote! {
|
||||
value: serde_json::Value,
|
||||
},
|
||||
quote! {
|
||||
.header("content-type", "application/json")
|
||||
.json_body(value)
|
||||
},
|
||||
),
|
||||
crate::method::OperationResponseType::Upgrade => {
|
||||
Default::default()
|
||||
}
|
||||
};
|
||||
|
||||
match status_code {
|
||||
OperationResponseStatus::Code(status_code) => {
|
||||
let canonical_reason =
|
||||
http::StatusCode::from_u16(*status_code)
|
||||
.unwrap()
|
||||
.canonical_reason()
|
||||
.unwrap();
|
||||
let fn_name = format_ident!(
|
||||
"{}",
|
||||
&sanitize(canonical_reason, Case::Snake)
|
||||
);
|
||||
|
||||
quote! {
|
||||
pub fn #fn_name(self, #value_param) -> Self {
|
||||
Self(self.0
|
||||
.status(#status_code)
|
||||
#value_use
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
OperationResponseStatus::Range(status_type) => {
|
||||
let status_string = match status_type {
|
||||
1 => "informational",
|
||||
2 => "success",
|
||||
3 => "redirect",
|
||||
4 => "client_error",
|
||||
5 => "server_error",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let fn_name = format_ident!("{}", status_string);
|
||||
quote! {
|
||||
pub fn #fn_name(self, status: u16, #value_param) -> Self {
|
||||
assert_eq!(status / 100u16, #status_type);
|
||||
Self(self.0
|
||||
.status(status)
|
||||
#value_use
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
OperationResponseStatus::Default => quote! {
|
||||
pub fn default_response(self, status: u16, #value_param) -> Self {
|
||||
Self(self.0
|
||||
.status(status)
|
||||
#value_use
|
||||
)
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let then_impl = quote! {
|
||||
impl #then {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
#(#then_methods)*
|
||||
}
|
||||
};
|
||||
|
||||
MockOp {
|
||||
when,
|
||||
when_impl,
|
||||
then,
|
||||
then_impl,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ pub use typify::TypeSpaceImpl as TypeImpl;
|
|||
pub use typify::TypeSpacePatch as TypePatch;
|
||||
|
||||
mod cli;
|
||||
mod httpmock;
|
||||
mod method;
|
||||
mod template;
|
||||
mod to_schema;
|
||||
|
@ -556,7 +557,7 @@ impl Generator {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn space_out_items(content: String) -> Result<String> {
|
||||
pub fn space_out_items(content: String) -> Result<String> {
|
||||
// Add newlines after end-braces at <= two levels of indentation.
|
||||
Ok(if cfg!(not(windows)) {
|
||||
let regex = regex::Regex::new(r#"(})(\n\s{0,8}[^} ])"#).unwrap();
|
||||
|
@ -567,6 +568,7 @@ pub(crate) fn space_out_items(content: String) -> Result<String> {
|
|||
})
|
||||
}
|
||||
|
||||
/// Do some very basic checks of the OpenAPI documents.
|
||||
pub fn validate_openapi(spec: &OpenAPI) -> Result<()> {
|
||||
match spec.openapi.as_str() {
|
||||
"3.0.0" | "3.0.1" | "3.0.2" | "3.0.3" => (),
|
||||
|
|
|
@ -22,17 +22,17 @@ use crate::{to_schema::ToSchema, util::ReferenceOrExt};
|
|||
pub(crate) struct OperationMethod {
|
||||
pub operation_id: String,
|
||||
pub tags: Vec<String>,
|
||||
method: HttpMethod,
|
||||
path: PathTemplate,
|
||||
pub method: HttpMethod,
|
||||
pub path: PathTemplate,
|
||||
pub summary: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub params: Vec<OperationParameter>,
|
||||
responses: Vec<OperationResponse>,
|
||||
pub responses: Vec<OperationResponse>,
|
||||
pub dropshot_paginated: Option<DropshotPagination>,
|
||||
dropshot_websocket: bool,
|
||||
}
|
||||
|
||||
enum HttpMethod {
|
||||
pub enum HttpMethod {
|
||||
Get,
|
||||
Put,
|
||||
Post,
|
||||
|
@ -140,8 +140,8 @@ impl FromStr for BodyContentType {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct OperationResponse {
|
||||
status_code: OperationResponseStatus,
|
||||
typ: OperationResponseType,
|
||||
pub status_code: OperationResponseStatus,
|
||||
pub typ: OperationResponseType,
|
||||
// TODO this isn't currently used because dropshot doesn't give us a
|
||||
// particularly useful message here.
|
||||
#[allow(dead_code)]
|
||||
|
|
|
@ -63,6 +63,31 @@ impl PathTemplate {
|
|||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn as_wildcard(&self) -> String {
|
||||
let inner = self
|
||||
.components
|
||||
.iter()
|
||||
.map(|c| match c {
|
||||
Component::Constant(name) => name.clone(),
|
||||
Component::Parameter(_) => ".*".to_string(),
|
||||
})
|
||||
.collect::<String>();
|
||||
format!("^{}$", inner)
|
||||
}
|
||||
|
||||
pub fn as_wildcard_param(&self, param: &str) -> String {
|
||||
let inner = self
|
||||
.components
|
||||
.iter()
|
||||
.map(|c| match c {
|
||||
Component::Constant(name) => name.clone(),
|
||||
Component::Parameter(p) if p == param => "{}".to_string(),
|
||||
Component::Parameter(_) => ".*".to_string(),
|
||||
})
|
||||
.collect::<String>();
|
||||
format!("^{}$", inner)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(t: &str) -> Result<PathTemplate> {
|
||||
|
|
|
@ -0,0 +1,976 @@
|
|||
pub mod operations {
|
||||
# and [`Then`](httpmock::Then)"]
|
||||
#![doc = r" wrappers for each operation. Each can be converted to"]
|
||||
#![doc = r" its inner type with a call to `into_inner()`. This can"]
|
||||
#![doc = r" be used to explicitly deviate from permitted values."]
|
||||
use sdk::*;
|
||||
pub struct ControlHoldWhen(httpmock::When);
|
||||
impl ControlHoldWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/control/hold$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ControlHoldThen(httpmock::Then);
|
||||
impl ControlHoldThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: ()) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ControlResumeWhen(httpmock::When);
|
||||
impl ControlResumeWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/control/resume$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ControlResumeThen(httpmock::Then);
|
||||
impl ControlResumeThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self) -> Self {
|
||||
Self(self.0.status(200u16))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskGetWhen(httpmock::When);
|
||||
impl TaskGetWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/v1/task/.*$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn task(self, value: &str) -> Self {
|
||||
let re = regex::Regex::new(&format!("^/v1/task/{}$", value.to_string())).unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskGetThen(httpmock::Then);
|
||||
impl TaskGetThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &types::Task) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TasksGetWhen(httpmock::When);
|
||||
impl TasksGetWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/v1/tasks$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TasksGetThen(httpmock::Then);
|
||||
impl TasksGetThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &Vec<types::Task>) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskSubmitWhen(httpmock::When);
|
||||
impl TaskSubmitWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/tasks$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::TaskSubmit) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskSubmitThen(httpmock::Then);
|
||||
impl TaskSubmitThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::TaskSubmitResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskEventsGetWhen(httpmock::When);
|
||||
impl TaskEventsGetWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/v1/tasks/.*/events$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn task(self, value: &str) -> Self {
|
||||
let re =
|
||||
regex::Regex::new(&format!("^/v1/tasks/{}/events$", value.to_string())).unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
|
||||
pub fn minseq(self, value: u32) -> Self {
|
||||
Self(self.0.query_param("minseq", value.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskEventsGetThen(httpmock::Then);
|
||||
impl TaskEventsGetThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &Vec<types::TaskEvent>) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskOutputsGetWhen(httpmock::When);
|
||||
impl TaskOutputsGetWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/v1/tasks/.*/outputs$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn task(self, value: &str) -> Self {
|
||||
let re =
|
||||
regex::Regex::new(&format!("^/v1/tasks/{}/outputs$", value.to_string())).unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskOutputsGetThen(httpmock::Then);
|
||||
impl TaskOutputsGetThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &Vec<types::TaskOutput>) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskOutputDownloadWhen(httpmock::When);
|
||||
impl TaskOutputDownloadWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/v1/tasks/.*/outputs/.*$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn task(self, value: &str) -> Self {
|
||||
let re = regex::Regex::new(&format!("^/v1/tasks/{}/outputs/.*$", value.to_string()))
|
||||
.unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
|
||||
pub fn output(self, value: &str) -> Self {
|
||||
let re = regex::Regex::new(&format!("^/v1/tasks/.*/outputs/{}$", value.to_string()))
|
||||
.unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaskOutputDownloadThen(httpmock::Then);
|
||||
impl TaskOutputDownloadThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn success(self, status: u16, value: serde_json::Value) -> Self {
|
||||
assert_eq!(status / 100u16, 2u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UserCreateWhen(httpmock::When);
|
||||
impl UserCreateWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/users$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::UserCreate) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UserCreateThen(httpmock::Then);
|
||||
impl UserCreateThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::UserCreateResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WhoamiWhen(httpmock::When);
|
||||
impl WhoamiWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/v1/whoami$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WhoamiThen(httpmock::Then);
|
||||
impl WhoamiThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &types::WhoamiResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerBootstrapWhen(httpmock::When);
|
||||
impl WorkerBootstrapWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/worker/bootstrap$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::WorkerBootstrap) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerBootstrapThen(httpmock::Then);
|
||||
impl WorkerBootstrapThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::WorkerBootstrapResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerPingWhen(httpmock::When);
|
||||
impl WorkerPingWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/v1/worker/ping$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerPingThen(httpmock::Then);
|
||||
impl WorkerPingThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &types::WorkerPingResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerTaskAppendWhen(httpmock::When);
|
||||
impl WorkerTaskAppendWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/worker/task/.*/append$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn task(self, value: &str) -> Self {
|
||||
let re = regex::Regex::new(&format!("^/v1/worker/task/{}/append$", value.to_string()))
|
||||
.unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::WorkerAppendTask) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerTaskAppendThen(httpmock::Then);
|
||||
impl WorkerTaskAppendThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self) -> Self {
|
||||
Self(self.0.status(201u16))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerTaskUploadChunkWhen(httpmock::When);
|
||||
impl WorkerTaskUploadChunkWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/worker/task/.*/chunk$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn task(self, value: &str) -> Self {
|
||||
let re = regex::Regex::new(&format!("^/v1/worker/task/{}/chunk$", value.to_string()))
|
||||
.unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
|
||||
pub fn body(self, value: serde_json::Value) -> Self {
|
||||
Self(self.0.json_body(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerTaskUploadChunkThen(httpmock::Then);
|
||||
impl WorkerTaskUploadChunkThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::UploadedChunk) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerTaskCompleteWhen(httpmock::When);
|
||||
impl WorkerTaskCompleteWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/worker/task/.*/complete$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn task(self, value: &str) -> Self {
|
||||
let re =
|
||||
regex::Regex::new(&format!("^/v1/worker/task/{}/complete$", value.to_string()))
|
||||
.unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::WorkerCompleteTask) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerTaskCompleteThen(httpmock::Then);
|
||||
impl WorkerTaskCompleteThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self) -> Self {
|
||||
Self(self.0.status(200u16))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerTaskAddOutputWhen(httpmock::When);
|
||||
impl WorkerTaskAddOutputWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/worker/task/.*/output$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn task(self, value: &str) -> Self {
|
||||
let re = regex::Regex::new(&format!("^/v1/worker/task/{}/output$", value.to_string()))
|
||||
.unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::WorkerAddOutput) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkerTaskAddOutputThen(httpmock::Then);
|
||||
impl WorkerTaskAddOutputThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self) -> Self {
|
||||
Self(self.0.status(201u16))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkersListWhen(httpmock::When);
|
||||
impl WorkersListWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/v1/workers$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkersListThen(httpmock::Then);
|
||||
impl WorkersListThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &types::WorkersResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkersRecycleWhen(httpmock::When);
|
||||
impl WorkersRecycleWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/v1/workers/recycle$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkersRecycleThen(httpmock::Then);
|
||||
impl WorkersRecycleThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self) -> Self {
|
||||
Self(self.0.status(200u16))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = r" An extension trait for [`MockServer`](httpmock::MockServer) that"]
|
||||
#[doc = r" adds a method for each operation. These are the equivalent of"]
|
||||
#[doc = r" type-checked [`mock()`](httpmock::MockServer::mock) calls."]
|
||||
pub trait MockServerExt {
|
||||
fn control_hold<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ControlHoldWhen, operations::ControlHoldThen);
|
||||
fn control_resume<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ControlResumeWhen, operations::ControlResumeThen);
|
||||
fn task_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskGetWhen, operations::TaskGetThen);
|
||||
fn tasks_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TasksGetWhen, operations::TasksGetThen);
|
||||
fn task_submit<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskSubmitWhen, operations::TaskSubmitThen);
|
||||
fn task_events_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskEventsGetWhen, operations::TaskEventsGetThen);
|
||||
fn task_outputs_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskOutputsGetWhen, operations::TaskOutputsGetThen);
|
||||
fn task_output_download<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskOutputDownloadWhen, operations::TaskOutputDownloadThen);
|
||||
fn user_create<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::UserCreateWhen, operations::UserCreateThen);
|
||||
fn whoami<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WhoamiWhen, operations::WhoamiThen);
|
||||
fn worker_bootstrap<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerBootstrapWhen, operations::WorkerBootstrapThen);
|
||||
fn worker_ping<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerPingWhen, operations::WorkerPingThen);
|
||||
fn worker_task_append<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerTaskAppendWhen, operations::WorkerTaskAppendThen);
|
||||
fn worker_task_upload_chunk<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerTaskUploadChunkWhen, operations::WorkerTaskUploadChunkThen);
|
||||
fn worker_task_complete<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerTaskCompleteWhen, operations::WorkerTaskCompleteThen);
|
||||
fn worker_task_add_output<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerTaskAddOutputWhen, operations::WorkerTaskAddOutputThen);
|
||||
fn workers_list<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkersListWhen, operations::WorkersListThen);
|
||||
fn workers_recycle<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkersRecycleWhen, operations::WorkersRecycleThen);
|
||||
}
|
||||
|
||||
impl MockServerExt for httpmock::MockServer {
|
||||
fn control_hold<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ControlHoldWhen, operations::ControlHoldThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::ControlHoldWhen::new(when),
|
||||
operations::ControlHoldThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn control_resume<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ControlResumeWhen, operations::ControlResumeThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::ControlResumeWhen::new(when),
|
||||
operations::ControlResumeThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn task_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskGetWhen, operations::TaskGetThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::TaskGetWhen::new(when),
|
||||
operations::TaskGetThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn tasks_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TasksGetWhen, operations::TasksGetThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::TasksGetWhen::new(when),
|
||||
operations::TasksGetThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn task_submit<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskSubmitWhen, operations::TaskSubmitThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::TaskSubmitWhen::new(when),
|
||||
operations::TaskSubmitThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn task_events_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskEventsGetWhen, operations::TaskEventsGetThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::TaskEventsGetWhen::new(when),
|
||||
operations::TaskEventsGetThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn task_outputs_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskOutputsGetWhen, operations::TaskOutputsGetThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::TaskOutputsGetWhen::new(when),
|
||||
operations::TaskOutputsGetThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn task_output_download<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::TaskOutputDownloadWhen, operations::TaskOutputDownloadThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::TaskOutputDownloadWhen::new(when),
|
||||
operations::TaskOutputDownloadThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn user_create<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::UserCreateWhen, operations::UserCreateThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::UserCreateWhen::new(when),
|
||||
operations::UserCreateThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn whoami<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WhoamiWhen, operations::WhoamiThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WhoamiWhen::new(when),
|
||||
operations::WhoamiThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn worker_bootstrap<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerBootstrapWhen, operations::WorkerBootstrapThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WorkerBootstrapWhen::new(when),
|
||||
operations::WorkerBootstrapThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn worker_ping<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerPingWhen, operations::WorkerPingThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WorkerPingWhen::new(when),
|
||||
operations::WorkerPingThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn worker_task_append<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerTaskAppendWhen, operations::WorkerTaskAppendThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WorkerTaskAppendWhen::new(when),
|
||||
operations::WorkerTaskAppendThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn worker_task_upload_chunk<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerTaskUploadChunkWhen, operations::WorkerTaskUploadChunkThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WorkerTaskUploadChunkWhen::new(when),
|
||||
operations::WorkerTaskUploadChunkThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn worker_task_complete<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerTaskCompleteWhen, operations::WorkerTaskCompleteThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WorkerTaskCompleteWhen::new(when),
|
||||
operations::WorkerTaskCompleteThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn worker_task_add_output<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkerTaskAddOutputWhen, operations::WorkerTaskAddOutputThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WorkerTaskAddOutputWhen::new(when),
|
||||
operations::WorkerTaskAddOutputThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn workers_list<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkersListWhen, operations::WorkersListThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WorkersListWhen::new(when),
|
||||
operations::WorkersListThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn workers_recycle<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::WorkersRecycleWhen, operations::WorkersRecycleThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::WorkersRecycleWhen::new(when),
|
||||
operations::WorkersRecycleThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,349 @@
|
|||
pub mod operations {
|
||||
# and [`Then`](httpmock::Then)"]
|
||||
#![doc = r" wrappers for each operation. Each can be converted to"]
|
||||
#![doc = r" its inner type with a call to `into_inner()`. This can"]
|
||||
#![doc = r" be used to explicitly deviate from permitted values."]
|
||||
use sdk::*;
|
||||
pub struct EnrolWhen(httpmock::When);
|
||||
impl EnrolWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/enrol$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn authorization(self, value: &str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::EnrolBody) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnrolThen(httpmock::Then);
|
||||
impl EnrolThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self) -> Self {
|
||||
Self(self.0.status(201u16))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GlobalJobsWhen(httpmock::When);
|
||||
impl GlobalJobsWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/global/jobs$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn authorization(self, value: &str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GlobalJobsThen(httpmock::Then);
|
||||
impl GlobalJobsThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::GlobalJobsResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PingWhen(httpmock::When);
|
||||
impl PingWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/ping$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn authorization(self, value: &str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PingThen(httpmock::Then);
|
||||
impl PingThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::PingResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReportFinishWhen(httpmock::When);
|
||||
impl ReportFinishWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/report/finish$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn authorization(self, value: &str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::ReportFinishBody) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReportFinishThen(httpmock::Then);
|
||||
impl ReportFinishThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::ReportResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReportOutputWhen(httpmock::When);
|
||||
impl ReportOutputWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/report/output$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn authorization(self, value: &str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::ReportOutputBody) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReportOutputThen(httpmock::Then);
|
||||
impl ReportOutputThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::ReportResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReportStartWhen(httpmock::When);
|
||||
impl ReportStartWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/report/start$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn authorization(self, value: &str) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::ReportStartBody) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReportStartThen(httpmock::Then);
|
||||
impl ReportStartThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::ReportResult) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = r" An extension trait for [`MockServer`](httpmock::MockServer) that"]
|
||||
#[doc = r" adds a method for each operation. These are the equivalent of"]
|
||||
#[doc = r" type-checked [`mock()`](httpmock::MockServer::mock) calls."]
|
||||
pub trait MockServerExt {
|
||||
fn enrol<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::EnrolWhen, operations::EnrolThen);
|
||||
fn global_jobs<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::GlobalJobsWhen, operations::GlobalJobsThen);
|
||||
fn ping<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::PingWhen, operations::PingThen);
|
||||
fn report_finish<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ReportFinishWhen, operations::ReportFinishThen);
|
||||
fn report_output<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ReportOutputWhen, operations::ReportOutputThen);
|
||||
fn report_start<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ReportStartWhen, operations::ReportStartThen);
|
||||
}
|
||||
|
||||
impl MockServerExt for httpmock::MockServer {
|
||||
fn enrol<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::EnrolWhen, operations::EnrolThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::EnrolWhen::new(when),
|
||||
operations::EnrolThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn global_jobs<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::GlobalJobsWhen, operations::GlobalJobsThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::GlobalJobsWhen::new(when),
|
||||
operations::GlobalJobsThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn ping<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::PingWhen, operations::PingThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::PingWhen::new(when),
|
||||
operations::PingThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn report_finish<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ReportFinishWhen, operations::ReportFinishThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::ReportFinishWhen::new(when),
|
||||
operations::ReportFinishThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn report_output<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ReportOutputWhen, operations::ReportOutputThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::ReportOutputWhen::new(when),
|
||||
operations::ReportOutputThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn report_start<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::ReportStartWhen, operations::ReportStartThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::ReportStartWhen::new(when),
|
||||
operations::ReportStartThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,67 @@
|
|||
pub mod operations {
|
||||
# and [`Then`](httpmock::Then)"]
|
||||
#![doc = r" wrappers for each operation. Each can be converted to"]
|
||||
#![doc = r" its inner type with a call to `into_inner()`. This can"]
|
||||
#![doc = r" be used to explicitly deviate from permitted values."]
|
||||
use sdk::*;
|
||||
pub struct KeyGetWhen(httpmock::When);
|
||||
impl KeyGetWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/key$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn key(self, value: bool) -> Self {
|
||||
Self(self.0.query_param("key", value.to_string()))
|
||||
}
|
||||
|
||||
pub fn unique_key(self, value: &str) -> Self {
|
||||
Self(self.0.query_param("unique_key", value.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct KeyGetThen(httpmock::Then);
|
||||
impl KeyGetThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self) -> Self {
|
||||
Self(self.0.status(200u16))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = r" An extension trait for [`MockServer`](httpmock::MockServer) that"]
|
||||
#[doc = r" adds a method for each operation. These are the equivalent of"]
|
||||
#[doc = r" type-checked [`mock()`](httpmock::MockServer::mock) calls."]
|
||||
pub trait MockServerExt {
|
||||
fn key_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::KeyGetWhen, operations::KeyGetThen);
|
||||
}
|
||||
|
||||
impl MockServerExt for httpmock::MockServer {
|
||||
fn key_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::KeyGetWhen, operations::KeyGetThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::KeyGetWhen::new(when),
|
||||
operations::KeyGetThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,518 @@
|
|||
pub mod operations {
|
||||
# and [`Then`](httpmock::Then)"]
|
||||
#![doc = r" wrappers for each operation. Each can be converted to"]
|
||||
#![doc = r" its inner type with a call to `into_inner()`. This can"]
|
||||
#![doc = r" be used to explicitly deviate from permitted values."]
|
||||
use sdk::*;
|
||||
pub struct InstanceGetWhen(httpmock::When);
|
||||
impl InstanceGetWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/instance$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceGetThen(httpmock::Then);
|
||||
impl InstanceGetThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &types::InstanceGetResponse) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 4u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 5u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceEnsureWhen(httpmock::When);
|
||||
impl InstanceEnsureWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::PUT)
|
||||
.path_matches(regex::Regex::new("^/instance$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::InstanceEnsureRequest) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceEnsureThen(httpmock::Then);
|
||||
impl InstanceEnsureThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn created(self, value: &types::InstanceEnsureResponse) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(201u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 4u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 5u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceIssueCrucibleSnapshotRequestWhen(httpmock::When);
|
||||
impl InstanceIssueCrucibleSnapshotRequestWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::POST)
|
||||
.path_matches(regex::Regex::new("^/instance/disk/.*/snapshot/.*$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn id(self, value: &uuid::Uuid) -> Self {
|
||||
let re = regex::Regex::new(&format!(
|
||||
"^/instance/disk/{}/snapshot/.*$",
|
||||
value.to_string()
|
||||
))
|
||||
.unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
|
||||
pub fn snapshot_id(self, value: &uuid::Uuid) -> Self {
|
||||
let re = regex::Regex::new(&format!(
|
||||
"^/instance/disk/.*/snapshot/{}$",
|
||||
value.to_string()
|
||||
))
|
||||
.unwrap();
|
||||
Self(self.0.path_matches(re))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceIssueCrucibleSnapshotRequestThen(httpmock::Then);
|
||||
impl InstanceIssueCrucibleSnapshotRequestThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: ()) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 4u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 5u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceMigrateStatusWhen(httpmock::When);
|
||||
impl InstanceMigrateStatusWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/instance/migrate/status$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::InstanceMigrateStatusRequest) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceMigrateStatusThen(httpmock::Then);
|
||||
impl InstanceMigrateStatusThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &types::InstanceMigrateStatusResponse) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 4u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 5u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceSerialWhen(httpmock::When);
|
||||
impl InstanceSerialWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/instance/serial$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceSerialThen(httpmock::Then);
|
||||
impl InstanceSerialThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn default_response(self, status: u16) -> Self {
|
||||
Self(self.0.status(status))
|
||||
}
|
||||
|
||||
pub fn switching_protocols(self) -> Self {
|
||||
Self(self.0.status(101u16))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceStatePutWhen(httpmock::When);
|
||||
impl InstanceStatePutWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::PUT)
|
||||
.path_matches(regex::Regex::new("^/instance/state$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn body(self, value: types::InstanceStateRequested) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceStatePutThen(httpmock::Then);
|
||||
impl InstanceStatePutThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn no_content(self) -> Self {
|
||||
Self(self.0.status(204u16))
|
||||
}
|
||||
|
||||
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 4u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 5u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceStateMonitorWhen(httpmock::When);
|
||||
impl InstanceStateMonitorWhen {
|
||||
pub fn new(inner: httpmock::When) -> Self {
|
||||
Self(
|
||||
inner
|
||||
.method(httpmock::Method::GET)
|
||||
.path_matches(regex::Regex::new("^/instance/state-monitor$").unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::When {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn body(self, value: &types::InstanceStateMonitorRequest) -> Self {
|
||||
Self(self.0.json_body_obj(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstanceStateMonitorThen(httpmock::Then);
|
||||
impl InstanceStateMonitorThen {
|
||||
pub fn new(inner: httpmock::Then) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> httpmock::Then {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn ok(self, value: &types::InstanceStateMonitorResponse) -> Self {
|
||||
Self(
|
||||
self.0
|
||||
.status(200u16)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 4u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
|
||||
assert_eq!(status / 100u16, 5u16);
|
||||
Self(
|
||||
self.0
|
||||
.status(status)
|
||||
.header("content-type", "application/json")
|
||||
.json_body_obj(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = r" An extension trait for [`MockServer`](httpmock::MockServer) that"]
|
||||
#[doc = r" adds a method for each operation. These are the equivalent of"]
|
||||
#[doc = r" type-checked [`mock()`](httpmock::MockServer::mock) calls."]
|
||||
pub trait MockServerExt {
|
||||
fn instance_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceGetWhen, operations::InstanceGetThen);
|
||||
fn instance_ensure<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceEnsureWhen, operations::InstanceEnsureThen);
|
||||
fn instance_issue_crucible_snapshot_request<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(
|
||||
operations::InstanceIssueCrucibleSnapshotRequestWhen,
|
||||
operations::InstanceIssueCrucibleSnapshotRequestThen,
|
||||
);
|
||||
fn instance_migrate_status<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceMigrateStatusWhen, operations::InstanceMigrateStatusThen);
|
||||
fn instance_serial<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceSerialWhen, operations::InstanceSerialThen);
|
||||
fn instance_state_put<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceStatePutWhen, operations::InstanceStatePutThen);
|
||||
fn instance_state_monitor<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceStateMonitorWhen, operations::InstanceStateMonitorThen);
|
||||
}
|
||||
|
||||
impl MockServerExt for httpmock::MockServer {
|
||||
fn instance_get<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceGetWhen, operations::InstanceGetThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::InstanceGetWhen::new(when),
|
||||
operations::InstanceGetThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn instance_ensure<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceEnsureWhen, operations::InstanceEnsureThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::InstanceEnsureWhen::new(when),
|
||||
operations::InstanceEnsureThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn instance_issue_crucible_snapshot_request<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(
|
||||
operations::InstanceIssueCrucibleSnapshotRequestWhen,
|
||||
operations::InstanceIssueCrucibleSnapshotRequestThen,
|
||||
),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::InstanceIssueCrucibleSnapshotRequestWhen::new(when),
|
||||
operations::InstanceIssueCrucibleSnapshotRequestThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn instance_migrate_status<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceMigrateStatusWhen, operations::InstanceMigrateStatusThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::InstanceMigrateStatusWhen::new(when),
|
||||
operations::InstanceMigrateStatusThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn instance_serial<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceSerialWhen, operations::InstanceSerialThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::InstanceSerialWhen::new(when),
|
||||
operations::InstanceSerialThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn instance_state_put<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceStatePutWhen, operations::InstanceStatePutThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::InstanceStatePutWhen::new(when),
|
||||
operations::InstanceStatePutThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn instance_state_monitor<F>(&self, config_fn: F) -> httpmock::Mock
|
||||
where
|
||||
F: FnOnce(operations::InstanceStateMonitorWhen, operations::InstanceStateMonitorThen),
|
||||
{
|
||||
self.mock(|when, then| {
|
||||
config_fn(
|
||||
operations::InstanceStateMonitorWhen::new(when),
|
||||
operations::InstanceStateMonitorThen::new(then),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -85,6 +85,25 @@ fn verify_apis(openapi_file: &str) {
|
|||
format!("tests/output/{}-cli.out", openapi_stem),
|
||||
&output,
|
||||
);
|
||||
|
||||
// httpmock generation.
|
||||
let code = generator.httpmock(&spec, "sdk").unwrap();
|
||||
|
||||
// TODO pending #368
|
||||
let output = rustfmt_wrapper::rustfmt_config(
|
||||
rustfmt_wrapper::config::Config {
|
||||
format_strings: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
code,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let output = progenitor_impl::space_out_items(output).unwrap();
|
||||
expectorate::assert_contents(
|
||||
format!("tests/output/{}-httpmock.out", openapi_stem),
|
||||
&output,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue