Skip to content

Commit

Permalink
feat: add workspace_path opt so tests runs w/ tmpfile
Browse files Browse the repository at this point in the history
Signed-off-by: WoodenMaiden <[email protected]>
  • Loading branch information
WoodenMaiden committed Nov 21, 2023
1 parent 8001149 commit a728af6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
5 changes: 4 additions & 1 deletion agent/lib/src/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ impl LambdoAgentService for LambdoAgentServer {
let request = request.into_inner();
debug!("Received request: {:?}", request);

let mut runner_engine = runner_engine::service::RunnerEngine::new(request);
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
7 changes: 7 additions & 0 deletions agent/lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const fn default_local_port() -> u16 {
0
}

fn default_workspace_path() -> String {
std::env::temp_dir().to_str().unwrap().to_string()
}

#[derive(Error, Debug)]
pub enum AgentConfigError {
#[error("cannot load config file")]
Expand All @@ -37,6 +41,9 @@ pub struct AgentConfig {
/// The gRPC configuration
#[serde(default = "default_grpc")]
pub grpc: GRPCConfig,
/// The workspace where the agent will store the files of Requests and their resulting files
#[serde(default = "default_workspace_path")]
pub workspace_path: String,
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
Expand Down
26 changes: 6 additions & 20 deletions agent/lib/src/runner_engine/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,12 @@ impl RunnerEngine {
/// # Arguments
///
/// * `request_message` - The request message
///
/// # Returns
///
/// * `Self` - The new instance of RunnerEngine
pub fn new(request_message: ExecuteRequest) -> Self {
Self {
request_message,
root_path: std::env::temp_dir(),
}
}

/// Create a new instance of RunnerEngine that uses another root path than /tmp
///
/// # Arguments
///
/// * `request_message` - The request message
/// * `root_path` - The root path of the workspace
///
/// # Returns
///
/// * `Self` - The new instance of RunnerEngine
pub fn new_with_path(request_message: ExecuteRequest, root_path: &str) -> Self {
pub fn new(request_message: ExecuteRequest, root_path: &str) -> Self {
Self {
request_message,
root_path: PathBuf::from(root_path),
Expand Down Expand Up @@ -217,13 +201,15 @@ mod tests {
use std::fs::File;
use std::io::Read;

const DEFAULT_WORKSPACE_PATH: &str = "/tmp";

#[test]
fn run_one_works_with_ouputs_and_code() {
let res = RunnerEngine::new(ExecuteRequest {
id: "".to_string(),
files: vec![],
steps: vec![],
})
}, DEFAULT_WORKSPACE_PATH)
.run_one("echo -n 'This is stdout' && echo -n 'This is stderr' >&2 && exit 1");

assert!(res.is_ok());
Expand Down Expand Up @@ -256,7 +242,7 @@ mod tests {
steps,
};

let mut api = RunnerEngine::new(request_data);
let mut api = RunnerEngine::new(request_data, DEFAULT_WORKSPACE_PATH);

let res = api.run().unwrap();

Expand Down Expand Up @@ -291,7 +277,7 @@ mod tests {
steps,
};

RunnerEngine::new_with_path(request_data, path.as_os_str().to_str().unwrap())
RunnerEngine::new(request_data, path.as_os_str().to_str().unwrap())
.create_workspace()
.unwrap();

Expand Down

0 comments on commit a728af6

Please sign in to comment.