WP-10: contract and failing tests for OS and package inventory
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@ -305,3 +305,66 @@ pub fn smtp() -> SmtpSettings {
|
||||
notify_to: vec!["ops@example.com".into()],
|
||||
}
|
||||
}
|
||||
|
||||
use domain::host::{Inventory, OsInfo, Package, PackageSource};
|
||||
use domain::ports::{HostInspector, InventoryRepository};
|
||||
|
||||
pub struct FakeInspector {
|
||||
pub fail: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl HostInspector for FakeInspector {
|
||||
async fn os_info(&self) -> Result<OsInfo, DomainError> {
|
||||
if self.fail {
|
||||
return Err(DomainError::Unavailable("host down".into()));
|
||||
}
|
||||
Ok(OsInfo {
|
||||
hostname: "srv".into(),
|
||||
name: "Debian GNU/Linux 12 (bookworm)".into(),
|
||||
version: "12".into(),
|
||||
kernel: "6.1.0-42-amd64".into(),
|
||||
uptime_secs: 3600,
|
||||
reboot_required: true,
|
||||
})
|
||||
}
|
||||
async fn packages(&self) -> Result<Vec<Package>, DomainError> {
|
||||
Ok(vec![
|
||||
Package {
|
||||
name: "bash".into(),
|
||||
source: PackageSource::Apt,
|
||||
installed: "5.2".into(),
|
||||
candidate: None,
|
||||
is_security: false,
|
||||
},
|
||||
Package {
|
||||
name: "openssl".into(),
|
||||
source: PackageSource::Apt,
|
||||
installed: "3.0.1".into(),
|
||||
candidate: Some("3.0.2".into()),
|
||||
is_security: true,
|
||||
},
|
||||
Package {
|
||||
name: "microk8s".into(),
|
||||
source: PackageSource::Snap,
|
||||
installed: "v1.32.13".into(),
|
||||
candidate: None,
|
||||
is_security: false,
|
||||
},
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MemInventory(pub Mutex<Option<Inventory>>);
|
||||
|
||||
#[async_trait]
|
||||
impl InventoryRepository for MemInventory {
|
||||
async fn save(&self, inventory: &Inventory) -> Result<(), DomainError> {
|
||||
*self.0.lock().unwrap() = Some(inventory.clone());
|
||||
Ok(())
|
||||
}
|
||||
async fn load(&self) -> Result<Option<Inventory>, DomainError> {
|
||||
Ok(self.0.lock().unwrap().clone())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user