mod body;
mod header;
mod method;
mod path;
mod query;
pub use body::*;
use caramelo::{MatchType::ToHave, Matcher, TypedMatcher};
pub use header::*;
pub use method::*;
pub use path::*;
pub use query::*;
use crate::mock::Request;
#[derive(Clone)]
pub enum HttpMatcher {
Path(Path),
Method(Method),
Header(Header),
HeaderValue(HeaderValue),
Jwt(Jwt),
BasicAuth(BasicAuth),
QueryParam(QueryParam),
QueryValue(QueryValue),
Body(Body),
#[cfg(feature = "json")]
ExactJson(BodyWithExactJson),
#[cfg(feature = "json")]
PartialJson(BodyWithPartialJson),
#[cfg(feature = "xml")]
ExactXml(BodyWithExactXml),
#[cfg(feature = "json")]
PartialXml(BodyWithPartialXml),
}
impl Matcher<Request> for HttpMatcher {
fn matches(&self, value: &Request) -> bool {
match self {
HttpMatcher::Path(path) => path.matches(value),
HttpMatcher::Method(method) => method.matches(value),
HttpMatcher::Header(header) => header.matches(value),
HttpMatcher::HeaderValue(header_value) => header_value.matches(value),
HttpMatcher::Jwt(jwt) => jwt.matches(value),
HttpMatcher::BasicAuth(basic_auth) => basic_auth.matches(value),
HttpMatcher::QueryParam(query) => query.matches(value),
HttpMatcher::QueryValue(query) => query.matches(value),
HttpMatcher::Body(body) => body.matches(value),
#[cfg(feature = "json")]
HttpMatcher::ExactJson(json) => json.matches(value),
#[cfg(feature = "json")]
HttpMatcher::PartialJson(json) => json.matches(value),
#[cfg(feature = "xml")]
HttpMatcher::ExactXml(xml) => xml.matches(value),
#[cfg(feature = "xml")]
HttpMatcher::PartialXml(xml) => xml.matches(value),
}
}
fn description(&self) -> String {
match self {
HttpMatcher::Path(path) => path.description(),
HttpMatcher::Method(method) => method.description(),
HttpMatcher::Header(header) => header.description(),
HttpMatcher::HeaderValue(header_value) => header_value.description(),
HttpMatcher::Jwt(jwt) => jwt.description(),
HttpMatcher::BasicAuth(basic_auth) => basic_auth.description(),
HttpMatcher::QueryParam(query) => query.description(),
HttpMatcher::QueryValue(query) => query.description(),
HttpMatcher::Body(body) => body.description(),
#[cfg(feature = "json")]
HttpMatcher::ExactJson(json) => json.description(),
#[cfg(feature = "json")]
HttpMatcher::PartialJson(json) => json.description(),
#[cfg(feature = "xml")]
HttpMatcher::ExactXml(xml) => xml.description(),
#[cfg(feature = "xml")]
HttpMatcher::PartialXml(xml) => xml.description(),
}
}
}
impl TypedMatcher<Request> for HttpMatcher {
fn matcher_type(&self) -> caramelo::MatchType {
ToHave
}
}