WP-11: contract and failing tests for package upgrades
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@ -368,3 +368,34 @@ impl InventoryRepository for MemInventory {
|
||||
Ok(self.0.lock().unwrap().clone())
|
||||
}
|
||||
}
|
||||
|
||||
use domain::ports::{HostUpdater, LineSink};
|
||||
|
||||
/// Records the requested packages and emits a few lines.
|
||||
#[derive(Default)]
|
||||
pub struct FakeUpdater {
|
||||
pub calls: Mutex<Vec<Vec<String>>>,
|
||||
pub fail: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl HostUpdater for FakeUpdater {
|
||||
async fn upgrade(&self, packages: &[String], out: &dyn LineSink) -> Result<(), DomainError> {
|
||||
self.calls.lock().unwrap().push(packages.to_vec());
|
||||
out.line("Reading package lists...");
|
||||
out.line(&format!(
|
||||
"Upgrading {} package(s)",
|
||||
if packages.is_empty() {
|
||||
"all".to_string()
|
||||
} else {
|
||||
packages.len().to_string()
|
||||
}
|
||||
));
|
||||
if self.fail {
|
||||
return Err(DomainError::Unavailable(
|
||||
"apt-get exited with status 100".into(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user