From edff1b37f4f62880e921e55401d5e0fb00c83858 Mon Sep 17 00:00:00 2001 From: WoodenMaiden Date: Mon, 27 Nov 2023 16:36:30 +0100 Subject: [PATCH] feat: use tmpfiles to mock runner_engine files Signed-off-by: WoodenMaiden --- agent/lib/src/api/server.rs | 6 ++---- agent/lib/src/runner_engine/service.rs | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/agent/lib/src/api/server.rs b/agent/lib/src/api/server.rs index d7380e5..35f21f5 100644 --- a/agent/lib/src/api/server.rs +++ b/agent/lib/src/api/server.rs @@ -84,10 +84,8 @@ impl LambdoAgentService for LambdoAgentServer { let request = request.into_inner(); debug!("Received request: {:?}", request); - let mut runner_engine = runner_engine::service::RunnerEngine::new( - request, - &self.config.workspace_path - ); + let mut runner_engine = + runner_engine::service::RunnerEngine::new(request, &self.config.workspace_path); let mut self_client = self.client.lock().await; if let Err(e) = runner_engine.create_workspace() { diff --git a/agent/lib/src/runner_engine/service.rs b/agent/lib/src/runner_engine/service.rs index 065ef3e..1723a40 100644 --- a/agent/lib/src/runner_engine/service.rs +++ b/agent/lib/src/runner_engine/service.rs @@ -201,15 +201,18 @@ mod tests { use std::fs::File; use std::io::Read; - const DEFAULT_WORKSPACE_PATH: &str = "/tmp"; + use tempfile::tempdir; #[test] fn run_one_works_with_ouputs_and_code() { - let res = RunnerEngine::new(ExecuteRequest { - id: "".to_string(), - files: vec![], - steps: vec![], - }, DEFAULT_WORKSPACE_PATH) + let res = RunnerEngine::new( + ExecuteRequest { + id: "".to_string(), + files: vec![], + steps: vec![], + }, + tempdir().unwrap().path().to_str().unwrap(), + ) .run_one("echo -n 'This is stdout' && echo -n 'This is stderr' >&2 && exit 1"); assert!(res.is_ok()); @@ -224,6 +227,10 @@ mod tests { /// Test the creation of a file #[test] fn workload_runs_correctly() { + let tempdir = tempfile::tempdir(); + let temp_dir = &tempdir.unwrap(); + let path = temp_dir.path(); + let files: Vec = Vec::new(); let steps: Vec = vec![ ExecuteRequestStep { @@ -242,7 +249,7 @@ mod tests { steps, }; - let mut api = RunnerEngine::new(request_data, DEFAULT_WORKSPACE_PATH); + let mut api = RunnerEngine::new(request_data, path.as_os_str().to_str().unwrap()); let res = api.run().unwrap();