autoendpoint/routers/stub/
client.rs

1use super::error::StubError;
2use super::settings::StubServerSettings;
3use crate::routers::RouterError;
4
5pub struct StubClient {
6    success: bool,
7    err: Option<StubError>,
8}
9
10impl StubClient {
11    /// Always succeeds
12    pub fn success() -> Self {
13        Self {
14            success: true,
15            err: None,
16        }
17    }
18
19    pub fn error(err: StubError) -> Self {
20        Self {
21            success: false,
22            err: Some(err),
23        }
24    }
25
26    /// Reply to the "client" based on the the type of app_id they specified.
27    pub async fn call(&self, settings: &StubServerSettings) -> Result<(), RouterError> {
28        if !self.success {
29            return Err(self
30                .err
31                .clone()
32                .unwrap_or(StubError::General(settings.error.clone()))
33                .into());
34        }
35
36        Ok(())
37    }
38}