//! 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; }