Skip to content

Commit

Permalink
feat: use tmpfiles to mock runner_engine files
Browse files Browse the repository at this point in the history
Signed-off-by: WoodenMaiden <[email protected]>
  • Loading branch information
WoodenMaiden committed Nov 27, 2023
1 parent a728af6 commit edff1b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 2 additions & 4 deletions agent/lib/src/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 14 additions & 7 deletions agent/lib/src/runner_engine/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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<FileModel> = Vec::new();
let steps: Vec<ExecuteRequestStep> = vec![
ExecuteRequestStep {
Expand All @@ -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();

Expand Down

0 comments on commit edff1b3

Please sign in to comment.