diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-02-27 18:31:49 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-04-03 16:46:17 +0000 |
| commit | 55e2e1d8cedb443b008b7ffb9c67d99daf1684cb (patch) | |
| tree | 9465c77029a7e6d82b0c2ca2f2404ac9c54c0599 | |
| parent | 3af96f92cb3becaeb8490ed0b5b13099a57686fb (diff) | |
| download | mullvadvpn-55e2e1d8cedb443b008b7ffb9c67d99daf1684cb.tar.xz mullvadvpn-55e2e1d8cedb443b008b7ffb9c67d99daf1684cb.zip | |
Don't run integration tests on Android
| -rw-r--r-- | mullvad-tests/src/bin/mock_openvpn.rs | 124 | ||||
| -rw-r--r-- | mullvad-tests/src/lib.rs | 2 |
2 files changed, 71 insertions, 55 deletions
diff --git a/mullvad-tests/src/bin/mock_openvpn.rs b/mullvad-tests/src/bin/mock_openvpn.rs index 042065d3be..03d38a4a09 100644 --- a/mullvad-tests/src/bin/mock_openvpn.rs +++ b/mullvad-tests/src/bin/mock_openvpn.rs @@ -1,70 +1,84 @@ -use mullvad_tests::{watch_event, PathWatcher}; -use std::{ - env, - fs::{self, File}, - io::{self, Read, Write}, - path::PathBuf, - sync::mpsc, - thread, - time::Duration, -}; +use crate::mock_openvpn::run; +fn main() { + run(); +} -const MAX_EVENT_TIME: Duration = Duration::from_secs(60); +#[cfg(target_os = "android")] +mod mock_openvpn { + pub fn run() {} +} -fn main() { - let (file, path) = create_args_file(); - let (finished_tx, finished_rx) = mpsc::channel(); - let watcher = PathWatcher::watch(&path).expect("Failed to watch file for events"); +#[cfg(not(target_os = "android"))] +mod mock_openvpn { + use mullvad_tests::{watch_event, PathWatcher}; + use std::{ + env, + fs::{self, File}, + io::{self, Read, Write}, + path::PathBuf, + sync::mpsc, + thread, + time::Duration, + }; - write_command_line(file); + const MAX_EVENT_TIME: Duration = Duration::from_secs(60); - wait_thread(wait_for_stdin_to_be_closed, finished_tx.clone()); - wait_thread( - move || wait_for_file_to_be_deleted(watcher, MAX_EVENT_TIME), - finished_tx, - ); + pub fn run() { + let (file, path) = create_args_file(); + let (finished_tx, finished_rx) = mpsc::channel(); + let watcher = PathWatcher::watch(&path).expect("Failed to watch file for events"); - let _ = finished_rx.recv(); - let _ = fs::remove_file(path); -} + write_command_line(file); -fn create_args_file() -> (File, PathBuf) { - let path = PathBuf::from( - env::var_os("MOCK_OPENVPN_ARGS_FILE").expect("Missing mock OpenVPN arguments file path"), - ); - let file = File::create(&path).expect("Failed to create mock OpenVPN arguments file"); + wait_thread(wait_for_stdin_to_be_closed, finished_tx.clone()); + wait_thread( + move || wait_for_file_to_be_deleted(watcher, MAX_EVENT_TIME), + finished_tx, + ); - (file, path) -} + let _ = finished_rx.recv(); + let _ = fs::remove_file(path); + } -fn write_command_line(mut file: File) { - for argument in env::args() { - let escaped_argument = argument - .replace("\\", "\\\\") - .replace("\n", "\\n") - .replace("\r", "\\r"); + fn create_args_file() -> (File, PathBuf) { + let path = PathBuf::from( + env::var_os("MOCK_OPENVPN_ARGS_FILE") + .expect("Missing mock OpenVPN arguments file path"), + ); + let file = File::create(&path).expect("Failed to create mock OpenVPN arguments file"); - writeln!(file, "{}", escaped_argument).expect("Failed to write argument to file"); + (file, path) } -} -fn wait_thread<F>(function: F, finished_tx: mpsc::Sender<()>) -where - F: FnOnce() + Send + 'static, -{ - thread::spawn(move || { - function(); - let _ = finished_tx.send(()); - }); -} + fn write_command_line(mut file: File) { + for argument in env::args() { + let escaped_argument = argument + .replace("\\", "\\\\") + .replace("\n", "\\n") + .replace("\r", "\\r"); -fn wait_for_stdin_to_be_closed() { - let _ignore_bytes = io::stdin().bytes().last(); -} + writeln!(file, "{}", escaped_argument).expect("Failed to write argument to file"); + } + } + + fn wait_thread<F>(function: F, finished_tx: mpsc::Sender<()>) + where + F: FnOnce() + Send + 'static, + { + thread::spawn(move || { + function(); + let _ = finished_tx.send(()); + }); + } + + fn wait_for_stdin_to_be_closed() { + let _ignore_bytes = io::stdin().bytes().last(); + } -fn wait_for_file_to_be_deleted(mut watcher: PathWatcher, timeout: Duration) { - let _ignore_event = watcher - .set_timeout(timeout) - .find(|&event| event == watch_event::REMOVE); + fn wait_for_file_to_be_deleted(mut watcher: PathWatcher, timeout: Duration) { + let _ignore_event = watcher + .set_timeout(timeout) + .find(|&event| event == watch_event::REMOVE); + } } diff --git a/mullvad-tests/src/lib.rs b/mullvad-tests/src/lib.rs index 243b0e3d99..fccb1354ca 100644 --- a/mullvad-tests/src/lib.rs +++ b/mullvad-tests/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_os = "android"))] + use self::{mock_openvpn::MOCK_OPENVPN_ARGS_FILE, platform_specific::*}; use futures::sync::oneshot; use jsonrpc_client_core::{Future, Transport}; |
