diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-12-27 14:38:36 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-01-08 11:34:07 +0100 |
| commit | 857febc80eaff8f5efc4239b2c625fcfbee78999 (patch) | |
| tree | ce29bea94421884ff91021efa8b43d21088edf3c /test/test-manager/src | |
| parent | aca939c260f718e3806a67b0a0703a33d4c8157f (diff) | |
| download | mullvadvpn-857febc80eaff8f5efc4239b2c625fcfbee78999.tar.xz mullvadvpn-857febc80eaff8f5efc4239b2c625fcfbee78999.zip | |
Add 'target_os' attribute to test macro
Diffstat (limited to 'test/test-manager/src')
| -rw-r--r-- | test/test-manager/src/config.rs | 10 | ||||
| -rw-r--r-- | test/test-manager/src/main.rs | 1 | ||||
| -rw-r--r-- | test/test-manager/src/run_tests.rs | 8 | ||||
| -rw-r--r-- | test/test-manager/src/tests/config.rs | 3 | ||||
| -rw-r--r-- | test/test-manager/src/tests/install.rs | 2 | ||||
| -rw-r--r-- | test/test-manager/src/tests/test_metadata.rs | 10 | ||||
| -rw-r--r-- | test/test-manager/src/tests/tunnel.rs | 4 | ||||
| -rw-r--r-- | test/test-manager/src/tests/ui.rs | 2 |
8 files changed, 33 insertions, 7 deletions
diff --git a/test/test-manager/src/config.rs b/test/test-manager/src/config.rs index 7145dca8a5..0acbeb322e 100644 --- a/test/test-manager/src/config.rs +++ b/test/test-manager/src/config.rs @@ -195,6 +195,16 @@ pub enum OsType { Macos, } +impl From<OsType> for test_rpc::meta::Os { + fn from(ostype: OsType) -> Self { + match ostype { + OsType::Windows => Self::Windows, + OsType::Linux => Self::Linux, + OsType::Macos => Self::Macos, + } + } +} + #[derive(clap::ValueEnum, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum PackageType { diff --git a/test/test-manager/src/main.rs b/test/test-manager/src/main.rs index 37a46c2580..78b951e90c 100644 --- a/test/test-manager/src/main.rs +++ b/test/test-manager/src/main.rs @@ -273,6 +273,7 @@ async fn main() -> Result<()> { host_bridge_name: crate::vm::network::macos::find_vm_bridge()?, #[cfg(not(target_os = "macos"))] host_bridge_name: crate::vm::network::linux::BRIDGE_NAME.to_owned(), + os: test_rpc::meta::Os::from(vm_config.os_type), }, &*instance, &test_filters, diff --git a/test/test-manager/src/run_tests.rs b/test/test-manager/src/run_tests.rs index 4a296ce288..b316511b06 100644 --- a/test/test-manager/src/run_tests.rs +++ b/test/test-manager/src/run_tests.rs @@ -1,5 +1,5 @@ use crate::summary::{self, maybe_log_test_result}; -use crate::tests::TestContext; +use crate::tests::{config::TEST_CONFIG, TestContext}; use crate::{ logging::{panic_as_string, TestOutput}, mullvad_daemon, tests, @@ -26,7 +26,7 @@ pub async fn run( mut summary_logger: Option<summary::SummaryLogger>, ) -> Result<()> { log::trace!("Setting test constants"); - tests::config::TEST_CONFIG.init(config); + TEST_CONFIG.init(config); let pty_path = instance.get_pty(); @@ -47,7 +47,9 @@ pub async fn run( let mullvad_client = mullvad_daemon::new_rpc_client(connection_handle, mullvad_daemon_transport); - let mut tests: Vec<_> = inventory::iter::<tests::TestMetadata>().collect(); + let mut tests: Vec<_> = inventory::iter::<tests::TestMetadata>() + .filter(|test| test.should_run_on_os(TEST_CONFIG.os)) + .collect(); tests.sort_by_key(|test| test.priority.unwrap_or(0)); if !test_filters.is_empty() { diff --git a/test/test-manager/src/tests/config.rs b/test/test-manager/src/tests/config.rs index a0a22368dd..7ffe737aa7 100644 --- a/test/test-manager/src/tests/config.rs +++ b/test/test-manager/src/tests/config.rs @@ -1,5 +1,6 @@ use once_cell::sync::OnceCell; use std::ops::Deref; +use test_rpc::meta::Os; // Default `mullvad_host`. This should match the production env. pub const DEFAULT_MULLVAD_HOST: &str = "mullvad.net"; @@ -20,6 +21,8 @@ pub struct TestConfig { pub mullvad_host: String, pub host_bridge_name: String, + + pub os: Os, } #[derive(Debug, Clone)] diff --git a/test/test-manager/src/tests/install.rs b/test/test-manager/src/tests/install.rs index 48ce233493..ec1344ede0 100644 --- a/test/test-manager/src/tests/install.rs +++ b/test/test-manager/src/tests/install.rs @@ -360,7 +360,7 @@ async fn replace_openvpn_cert(rpc: &ServiceClient) -> Result<(), Error> { const SOURCE_CERT_FILENAME: &str = "openvpn.ca.crt"; const DEST_CERT_FILENAME: &str = "ca.crt"; - let dest_dir = match rpc.get_os().await.expect("failed to get OS") { + let dest_dir = match TEST_CONFIG.os { Os::Windows => "C:\\Program Files\\Mullvad VPN\\resources", Os::Linux => "/opt/Mullvad VPN/resources", Os::Macos => "/Applications/Mullvad VPN.app/Contents/Resources", diff --git a/test/test-manager/src/tests/test_metadata.rs b/test/test-manager/src/tests/test_metadata.rs index 39d802e5e0..3e28a4380b 100644 --- a/test/test-manager/src/tests/test_metadata.rs +++ b/test/test-manager/src/tests/test_metadata.rs @@ -1,9 +1,11 @@ use super::TestWrapperFunction; +use test_rpc::meta::Os; use test_rpc::mullvad_daemon::MullvadClientVersion; pub struct TestMetadata { pub name: &'static str, pub command: &'static str, + pub target_os: Option<Os>, pub mullvad_client_version: MullvadClientVersion, pub func: TestWrapperFunction, pub priority: Option<i32>, @@ -12,5 +14,13 @@ pub struct TestMetadata { pub cleanup: bool, } +impl TestMetadata { + pub fn should_run_on_os(&self, os: Os) -> bool { + self.target_os + .map(|target_os| target_os == os) + .unwrap_or(true) + } +} + // Register our test metadata struct with inventory to allow submitting tests of this type. inventory::collect!(TestMetadata); diff --git a/test/test-manager/src/tests/tunnel.rs b/test/test-manager/src/tests/tunnel.rs index d36ba4febe..9544f098b2 100644 --- a/test/test-manager/src/tests/tunnel.rs +++ b/test/test-manager/src/tests/tunnel.rs @@ -1,7 +1,7 @@ use super::helpers::{ self, connect_and_wait, disconnect_and_wait, set_bridge_settings, set_relay_settings, }; -use super::{Error, TestContext}; +use super::{config::TEST_CONFIG, Error, TestContext}; use crate::network_monitor::{start_packet_monitor, MonitorOptions}; use mullvad_management_interface::{types, ManagementServiceClient}; @@ -502,7 +502,7 @@ async fn check_tunnel_psk( mullvad_client: &ManagementServiceClient, should_have_psk: bool, ) { - match rpc.get_os().await.expect("failed to get OS") { + match TEST_CONFIG.os { Os::Linux => { let name = helpers::get_tunnel_interface(mullvad_client.clone()) .await diff --git a/test/test-manager/src/tests/ui.rs b/test/test-manager/src/tests/ui.rs index 3600eb1d27..461d20ae10 100644 --- a/test/test-manager/src/tests/ui.rs +++ b/test/test-manager/src/tests/ui.rs @@ -32,7 +32,7 @@ pub async fn run_test_env< let new_params: Vec<String>; let bin_path; - match rpc.get_os().await? { + match TEST_CONFIG.os { Os::Linux => { bin_path = PathBuf::from("/usr/bin/xvfb-run"); |
