Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoel committed Dec 27, 2019
1 parent d9528fb commit bde47ff
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/process_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,43 @@ impl ProcessReturn {
}
}
}

#[test]
pub fn process_return_new() {
let process_return = ProcessReturn::new(123, "this is a message");
assert_eq!(123, process_return.get_code());
assert_eq!(
&"this is a message".to_string(),
process_return.get_message()
);
assert_eq!(0, process_return.get_output_paths().len());
}

#[test]
pub fn process_return_new_with_output_paths() {
let output_path = "/path/to/output";
let mut output_paths = vec![];
output_paths.push(output_path.to_string());
let process_return = ProcessReturn::new(123, "this is a message").with_output_paths(output_paths);
assert_eq!(123, process_return.get_code());
assert_eq!(
&"this is a message".to_string(),
process_return.get_message()
);
assert_eq!(1, process_return.get_output_paths().len());
assert_eq!(
output_path,
process_return.get_output_paths().get(0).unwrap()
);
}

#[test]
pub fn process_return_new_error() {
let process_return = ProcessReturn::new_error("this is an error message");
assert_eq!(ProcessReturn::get_error_code(), process_return.get_code());
assert_eq!(
&"this is an error message".to_string(),
process_return.get_message()
);
assert_eq!(0, process_return.get_output_paths().len());
}
31 changes: 31 additions & 0 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,34 @@ pub fn test_c_binding_failing_process() {
assert_eq!(returned_code.get_message(), "Something went wrong...");
assert!(returned_code.get_output_paths().is_empty());
}

#[test]
pub fn test_c_worker_library_env_var() {
let fake_path = "/path/to/nowhere/where/there/is/nothing";
std::env::set_var("WORKER_LIBRARY_FILE", fake_path);
let library_path = get_library_file_path();
assert_eq!(library_path, fake_path);
std::env::remove_var("WORKER_LIBRARY_FILE");
}

#[test]
pub fn test_c_worker_library_failure_on_get_worker_function_string_value() {
std::env::set_var(
"WORKER_LIBRARY_FILE",
"/path/to/nowhere/where/there/is/nothing",
);
let result = std::panic::catch_unwind(|| get_worker_function_string_value("fake_function"));
assert!(result.is_err());
std::env::remove_var("WORKER_LIBRARY_FILE");
}

#[test]
pub fn test_c_worker_library_failure_on_get_worker_parameters() {
std::env::set_var(
"WORKER_LIBRARY_FILE",
"/path/to/nowhere/where/there/is/nothing",
);
let result = std::panic::catch_unwind(|| get_worker_parameters());
assert!(result.is_err());
std::env::remove_var("WORKER_LIBRARY_FILE");
}

0 comments on commit bde47ff

Please sign in to comment.