omaha_client/installer/
stub.rs1use super::*;
10use crate::{
11 cup_ecdsa::RequestMetadata, protocol::response::Response, request_builder::RequestParams,
12};
13use futures::future::LocalBoxFuture;
14use futures::prelude::*;
15use thiserror::Error;
16
17#[derive(Debug, Error, Eq, PartialEq)]
22pub enum StubInstallErrors {
23 #[error("Stub Installer Failure")]
24 Failed,
25}
26
27pub struct StubPlan;
30
31impl Plan for StubPlan {
32 fn id(&self) -> String {
33 String::new()
34 }
35}
36
37#[derive(Debug, Default)]
41pub struct StubInstaller {
42 pub should_fail: bool,
43}
44
45impl Installer for StubInstaller {
46 type InstallPlan = StubPlan;
47 type Error = StubInstallErrors;
48 type InstallResult = ();
49
50 fn perform_install(
54 &mut self,
55 _install_plan: &StubPlan,
56 _observer: Option<&dyn ProgressObserver>,
57 ) -> LocalBoxFuture<'_, (Self::InstallResult, Vec<AppInstallResult<Self::Error>>)> {
58 if self.should_fail {
59 future::ready(((), vec![AppInstallResult::Failed(StubInstallErrors::Failed)]))
60 .boxed_local()
61 } else {
62 future::ready(((), vec![AppInstallResult::Installed])).boxed_local()
63 }
64 }
65
66 fn perform_reboot(&mut self) -> LocalBoxFuture<'_, Result<(), anyhow::Error>> {
67 future::ready(Ok(())).boxed_local()
68 }
69
70 fn try_create_install_plan<'a>(
71 &'a self,
72 _request_params: &'a RequestParams,
73 _request_metadata: Option<&'a RequestMetadata>,
74 response: &'a Response,
75 _response_bytes: Vec<u8>,
76 _ecdsa_signature: Option<Vec<u8>>,
77 ) -> LocalBoxFuture<'a, Result<Self::InstallPlan, Self::Error>> {
78 if response.protocol_version != "3.0" {
79 future::ready(Err(StubInstallErrors::Failed)).boxed_local()
80 } else {
81 future::ready(Ok(StubPlan)).boxed_local()
82 }
83 }
84}