cloudflare/framework/
mock.rs1use surf::http::Method;
2
3use crate::framework::async_api;
4use crate::framework::endpoint::Endpoint;
5use crate::framework::ApiResultTraits;
6use async_trait::async_trait;
7use surf::http::Result;
8
9pub struct MockApiClient {}
10
11pub struct NoopEndpoint {}
13
14impl Endpoint<NoopResult> for NoopEndpoint {
15 fn method(&self) -> Method {
16 Method::Get
17 }
18 fn path(&self) -> String {
19 "no/such/path/".to_owned()
20 }
21}
22
23#[derive(Deserialize, Debug)]
24pub struct NoopResult {}
25impl ApiResultTraits for NoopResult {}
26
27fn mock_response() -> surf::Error {
28 surf::Error::new(
29 surf::http::StatusCode::InternalServerError,
30 anyhow::Error::msg("This is a mocked failure response".to_owned()),
31 )
32}
33
34#[async_trait]
35impl async_api::AsyncApiClient for MockApiClient {
36 async fn request<ResultType, QueryType, BodyType>(
37 &self,
38 _endpoint: &(dyn Endpoint<ResultType, QueryType, BodyType> + Send + Sync),
39 ) -> Result<ResultType> {
40 Err(mock_response())
41 }
42}