diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/process.rs | 36 | ||||
| -rw-r--r-- | tests/util.rs | 16 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/process.rs b/tests/process.rs new file mode 100644 index 0000000000..2281a9d990 --- /dev/null +++ b/tests/process.rs @@ -0,0 +1,36 @@ +extern crate talpid_core; + +mod util; + +use talpid_core::process::OpenVpnBuilder; + +#[cfg(target_os = "linux")] +#[test] +fn check_test_environment() { + use std::env; + let test_threads = env::var("RUST_TEST_THREADS"); + if !test_threads.is_ok() || test_threads.unwrap() != "1" { + panic!("Tests must be run with environment variable RUST_TEST_THREADS=1"); + } +} + +#[cfg(target_os = "linux")] +#[test] +fn openvpn_builder_starts_correct_process() { + let mut child = OpenVpnBuilder::new("echo").spawn().unwrap(); + let args = util::read_args_for_proc(child.id()); + + assert_eq!(vec!["echo"], args); + child.kill().unwrap(); +} + +#[cfg(target_os = "linux")] +#[test] +fn openvpn_builder_passes_config() { + let config_path = "/path/to/config".to_owned(); + let mut child = OpenVpnBuilder::new("echo").config(&config_path).spawn().unwrap(); + let args = util::read_args_for_proc(child.id()); + + assert!(args.contains(&config_path)); + child.kill().unwrap(); +} diff --git a/tests/util.rs b/tests/util.rs new file mode 100644 index 0000000000..8fe87e5783 --- /dev/null +++ b/tests/util.rs @@ -0,0 +1,16 @@ +use std::fs::File; +use std::io::Read; +use std::path::Path; + +pub fn read_file<P: AsRef<Path>>(path: P) -> String { + let mut string = String::new(); + let mut f = File::open(path).unwrap(); + f.read_to_string(&mut string).unwrap(); + string +} + +#[cfg(target_os = "linux")] +pub fn read_args_for_proc(pid: u32) -> Vec<String> { + let cmdline = read_file(format!("/proc/{}/cmdline", pid)); + cmdline.split_terminator('\0').map(String::from).collect() +} |
