-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmanager.rs
More file actions
71 lines (64 loc) · 2.16 KB
/
Copy pathmanager.rs
File metadata and controls
71 lines (64 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! This module manages package operations such as installation, removal, and updates.
use crate::agent_control::agent_id::AgentID;
use crate::agent_type::runtime_config::on_host::package::rendered::{Oci, PostDownloadHook};
use crate::package::oci::package_manager::OCIPackageManagerError;
use std::path::PathBuf;
/// Information required to reference and install a package
#[derive(Debug, Clone, PartialEq)]
pub struct PackageData {
pub id: String, // same type as the packages map on an agent type definition
pub oci: Oci,
pub post_download_hook: Option<PostDownloadHook>,
}
/// Information about an installed package
#[derive(Debug, Clone, PartialEq)]
pub struct InstalledPackageData {
pub id: String, // same type as the packages map on an agent type definition
pub installation_path: PathBuf,
}
/// An interface for a package manager.
///
/// This trait has associated types for the error, the package to install and the installed package.
///
/// Given the intended usage for this trait is host-based, implementations will likely rely on
/// filesystem interaction.
pub trait PackageManager: Send + Sync {
/// Install a package.
fn install(
&self,
agent_id: &AgentID,
package: PackageData,
) -> Result<InstalledPackageData, OCIPackageManagerError>;
/// Uninstall a package.
fn uninstall(
&self,
agent_id: &AgentID,
package: InstalledPackageData,
) -> Result<(), OCIPackageManagerError>;
}
#[cfg(test)]
pub mod tests {
use super::*;
use mockall::mock;
use std::sync::Arc;
mock! {
pub PackageManager {}
impl PackageManager for PackageManager {
fn install(
&self,
agent_id: &AgentID,
package: PackageData,
) -> Result<InstalledPackageData, OCIPackageManagerError>;
fn uninstall(
&self,
agent_id: &AgentID,
package: InstalledPackageData,
) -> Result<(), OCIPackageManagerError>;
}
}
impl MockPackageManager {
pub fn new_arc() -> Arc<Self> {
Arc::new(MockPackageManager::new())
}
}
}