Files
pruefwerk/compliance-agent/tests/retention.rs
T
sharang 6752f54036
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 53s
CI / Deploy Agent (push) Successful in 4m12s
feat(retention): deleting a target or erasing a tenant removes its files (#289) (#355)
2026-09-23 16:12:09 +00:00

52 lines
1.7 KiB
Rust

//! Deleting a target removes its files from disk, not only its records
//! (#289). Drives the real API against a live Mongo (`TEST_MONGODB_URI`).
#![allow(clippy::expect_used, clippy::unwrap_used)]
mod common;
use common::TestServer;
#[tokio::test]
async fn deleting_a_target_removes_its_upload() {
let server = TestServer::start().await;
let created: serde_json::Value = server
.post(
"/api/v1/targets",
&serde_json::json!({ "name": "to-delete", "target_type": "firmware_rtos" }),
)
.await
.json()
.await
.unwrap();
let id = created["data"]["_id"]["$oid"].as_str().unwrap().to_string();
let form = reqwest::multipart::Form::new()
.text("kind", "source_archive")
.part(
"file",
reqwest::multipart::Part::bytes(b"int main(void) { return 0; }\n".to_vec())
.file_name("main.c"),
);
let uploaded = server
.client
.post(format!(
"{}/api/v1/targets/{id}/artifacts/upload",
server.base_url
))
.multipart(form)
.send()
.await
.unwrap();
assert!(uploaded.status().is_success(), "{}", uploaded.status());
// The test config's artifact store (see common::dev_config).
let upload_dir =
std::path::Path::new("/tmp/compliance-scanner-tests/artifacts/uploads").join(&id);
assert!(upload_dir.exists(), "the upload is on disk");
let deleted = server.delete(&format!("/api/v1/targets/{id}")).await;
assert!(deleted.status().is_success());
assert!(!upload_dir.exists(), "the upload is gone with the target");
server.cleanup().await;
}