Skip to content

Commit

Permalink
test(api): test parse_response
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-langlet committed Oct 30, 2023
1 parent 5f075fc commit bc8cbee
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,63 @@ fn parse_response(response: ExecuteResponse) -> RunResponse {
stderr,
}
}

#[cfg(test)]
mod test{
use crate::{vm_manager::grpc_definitions::{ExecuteResponse, ExecuteResponseStep}, api::parse_response};


#[test]
fn test_parse_response_stdout() {
let response = ExecuteResponse {
id: "test".to_string(),
steps: vec![
ExecuteResponseStep {
command: "echo Hello".to_string(),
stdout: "Hello".to_string(),
stderr: "".to_string(),
exit_code: 0,
},
ExecuteResponseStep {
command: "echo World".to_string(),
stdout: "World".to_string(),
stderr: "".to_string(),
exit_code: 0,
},
],
};

let parsed = parse_response(response);

assert_eq!(parsed.stdout, "HelloWorld");
assert_eq!(parsed.stderr, "");
assert_eq!(parsed.status, 0);
}

#[test]
fn test_parse_response_with_error() {
let response = ExecuteResponse {
id: "test".to_string(),
steps: vec![
ExecuteResponseStep {
command: "echo Hello".to_string(),
stdout: "Hello".to_string(),
stderr: "".to_string(),
exit_code: 0,
},
ExecuteResponseStep {
command: "echo World".to_string(),
stdout: "".to_string(),
stderr: "Error".to_string(),
exit_code: 1,
},
],
};

let parsed = parse_response(response);

assert_eq!(parsed.stdout, "Hello");
assert_eq!(parsed.stderr, "Error");
assert_eq!(parsed.status, 1);
}
}

0 comments on commit bc8cbee

Please sign in to comment.