diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-04-09 13:14:49 +0200 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-04-12 15:01:18 +0200 |
| commit | 39cac2951a0a63814541cade4f0f80b33bbbd18d (patch) | |
| tree | 5d83a31ece1d56e9e6623714c2a470d6c72bfa6a /test/test-manager/src | |
| parent | 94c3ce99aebd53f8c740fe093d03f06f483ea692 (diff) | |
| download | mullvadvpn-39cac2951a0a63814541cade4f0f80b33bbbd18d.tar.xz mullvadvpn-39cac2951a0a63814541cade4f0f80b33bbbd18d.zip | |
Get rid of type casting for test function argument
Replace the `Box<dyn Any>` type for the third test function argument
'mullvad client' - replace it with a dedicated enum type
`MullvadClientArgument`. This change got rid of the type casting from
`Box<dyn Any>` to `MullvadProxyClient` done in the `test_function` macro.
Diffstat (limited to 'test/test-manager/src')
| -rw-r--r-- | test/test-manager/src/mullvad_daemon.rs | 15 | ||||
| -rw-r--r-- | test/test-manager/src/run_tests.rs | 14 | ||||
| -rw-r--r-- | test/test-manager/src/tests/mod.rs | 9 |
3 files changed, 19 insertions, 19 deletions
diff --git a/test/test-manager/src/mullvad_daemon.rs b/test/test-manager/src/mullvad_daemon.rs index e1a7680cb4..115a09e049 100644 --- a/test/test-manager/src/mullvad_daemon.rs +++ b/test/test-manager/src/mullvad_daemon.rs @@ -51,14 +51,17 @@ pub struct RpcClientProvider { service: DummyService, } +pub enum MullvadClientArgument { + WithClient(MullvadProxyClient), + None, +} + impl RpcClientProvider { - pub async fn as_type( - &self, - client_type: MullvadClientVersion, - ) -> Box<dyn std::any::Any + Send> { + /// Whether a [test case](test_macro::test_function) needs a [`MullvadProxyClient`]. + pub async fn mullvad_client(&self, client_type: MullvadClientVersion) -> MullvadClientArgument { match client_type { - MullvadClientVersion::New => Box::new(self.new_client().await), - MullvadClientVersion::None => Box::new(()), + MullvadClientVersion::New => MullvadClientArgument::WithClient(self.new_client().await), + MullvadClientVersion::None => MullvadClientArgument::None, } } diff --git a/test/test-manager/src/run_tests.rs b/test/test-manager/src/run_tests.rs index 0c7868e529..005d0c89d4 100644 --- a/test/test-manager/src/run_tests.rs +++ b/test/test-manager/src/run_tests.rs @@ -1,6 +1,6 @@ use crate::{ logging::{panic_as_string, TestOutput}, - mullvad_daemon, + mullvad_daemon::{self, MullvadClientArgument}, summary::{self, maybe_log_test_result}, tests::{self, config::TEST_CONFIG, get_tests, TestContext}, vm, @@ -80,9 +80,9 @@ pub async fn run( let logger = super::logging::Logger::get_or_init(); for test in tests { - let mclient = test_context + let mullvad_client = test_context .rpc_provider - .as_type(test.mullvad_client_version) + .mullvad_client(test.mullvad_client_version) .await; log::info!("Running {}", test.name); @@ -94,7 +94,7 @@ pub async fn run( let test_result = run_test( client.clone(), - mclient, + mullvad_client, &test.func, test.name, test_context.clone(), @@ -175,15 +175,15 @@ pub async fn run( final_result } -pub async fn run_test<F, R, MullvadClient>( +pub async fn run_test<F, R>( runner_rpc: ServiceClient, - mullvad_rpc: MullvadClient, + mullvad_rpc: MullvadClientArgument, test: &F, test_name: &'static str, test_context: super::tests::TestContext, ) -> TestOutput where - F: Fn(super::tests::TestContext, ServiceClient, MullvadClient) -> R, + F: Fn(super::tests::TestContext, ServiceClient, MullvadClientArgument) -> R, R: Future<Output = anyhow::Result<()>>, { let _flushed = runner_rpc.try_poll_output().await; diff --git a/test/test-manager/src/tests/mod.rs b/test/test-manager/src/tests/mod.rs index f4c4563bde..b89b4f0fd0 100644 --- a/test/test-manager/src/tests/mod.rs +++ b/test/test-manager/src/tests/mod.rs @@ -13,7 +13,7 @@ mod tunnel; mod tunnel_state; mod ui; -use crate::mullvad_daemon::RpcClientProvider; +use crate::mullvad_daemon::{MullvadClientArgument, RpcClientProvider}; use anyhow::Context; pub use test_metadata::TestMetadata; use test_rpc::ServiceClient; @@ -30,11 +30,8 @@ pub struct TestContext { pub rpc_provider: RpcClientProvider, } -pub type TestWrapperFunction = fn( - TestContext, - ServiceClient, - Box<dyn std::any::Any + Send>, -) -> BoxFuture<'static, anyhow::Result<()>>; +pub type TestWrapperFunction = + fn(TestContext, ServiceClient, MullvadClientArgument) -> BoxFuture<'static, anyhow::Result<()>>; #[derive(thiserror::Error, Debug)] pub enum Error { |
