omaha_client/installer/
stub.rsuse super::*;
use crate::{
cup_ecdsa::RequestMetadata, protocol::response::Response, request_builder::RequestParams,
};
use futures::future::LocalBoxFuture;
use futures::prelude::*;
use thiserror::Error;
#[derive(Debug, Error, Eq, PartialEq)]
pub enum StubInstallErrors {
#[error("Stub Installer Failure")]
Failed,
}
pub struct StubPlan;
impl Plan for StubPlan {
fn id(&self) -> String {
String::new()
}
}
#[derive(Debug, Default)]
pub struct StubInstaller {
pub should_fail: bool,
}
impl Installer for StubInstaller {
type InstallPlan = StubPlan;
type Error = StubInstallErrors;
type InstallResult = ();
fn perform_install(
&mut self,
_install_plan: &StubPlan,
_observer: Option<&dyn ProgressObserver>,
) -> LocalBoxFuture<'_, (Self::InstallResult, Vec<AppInstallResult<Self::Error>>)> {
if self.should_fail {
future::ready((
(),
vec![AppInstallResult::Failed(StubInstallErrors::Failed)],
))
.boxed_local()
} else {
future::ready(((), vec![AppInstallResult::Installed])).boxed_local()
}
}
fn perform_reboot(&mut self) -> LocalBoxFuture<'_, Result<(), anyhow::Error>> {
future::ready(Ok(())).boxed_local()
}
fn try_create_install_plan<'a>(
&'a self,
_request_params: &'a RequestParams,
_request_metadata: Option<&'a RequestMetadata>,
response: &'a Response,
_response_bytes: Vec<u8>,
_ecdsa_signature: Option<Vec<u8>>,
) -> LocalBoxFuture<'a, Result<Self::InstallPlan, Self::Error>> {
if response.protocol_version != "3.0" {
future::ready(Err(StubInstallErrors::Failed)).boxed_local()
} else {
future::ready(Ok(StubPlan)).boxed_local()
}
}
}