use std::path::Path;
use std::process::Command;
#[derive(Debug, thiserror::Error)]
pub enum DestroyError {
#[error("az command failed: {0}")]
AzFailed(String),
#[error("io: {0}")]
Io(#[from] std::io::Error),
}
pub fn run(app_name: &str, resource_group: &str) -> Result<(), DestroyError> {
let status = Command::new("az")
.args([
"containerapp",
"delete",
"--name",
app_name,
"--resource-group",
resource_group,
"--yes",
])
.status()?;
if !status.success() {
return Err(DestroyError::AzFailed(format!(
"containerapp delete failed for '{app_name}'"
)));
}
Ok(())
}
pub fn remove_snapshot(snapshot_path: &Path) {
let _ = std::fs::remove_file(snapshot_path);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn destroy_error_formats_correctly() {
let err = DestroyError::AzFailed("containerapp not found".to_string());
assert!(err.to_string().contains("az command failed"));
assert!(err.to_string().contains("containerapp not found"));
}
}